Why do I get Parameter ? has no default value

Why do I get Parameter has no default value

Here is part of the form_load event

Why isn't Dim ID As Integer = 207 the default value

My intention is to set ID's value to the selected value of a comboboxes' selected item.  I'm trying to get this right first.

dennist
 

        Dim ID As Integer = 207
        Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\HasbaraSample.mdb;Persist Security Info=True")
        cn.Open()
        Dim strSQL As String = "SELECT KSGroups.KSGroup, KSGroups.ID FROM KSGroups INNER JOIN (KeywordSets INNER JOIN KSGroupKSAssignments ON KeywordSets.ID = KSGroupKSAssignments.KeywordSetID) ON KSGroups.ID = KSGroupKSAssignments.KSGroupID WHERE (((KeywordSets.ID)=[ ])) ORDER BY KSGroups.KSGroup"
        Dim da As OleDbDataAdapter = New OleDbDataAdapter
        Dim cmd As New OleDbCommand
        da.SelectCommand = cmd
        cmd.Connection = cn
        cmd.CommandText = strSQL
        da.SelectCommand.Parameters.Add("@ID", OleDb.OleDbType.Integer, 4, "ID")
        Dim ds As DataSet = New DataSet
        da.Fill(ds, "KSGroups")
        Me.AssignedListBox.ValueMember = ds.Tables("KSGroups").Columns(1).ColumnName
        Me.AssignedListBox.DisplayMember = ds.Tables("KSGroups").Columns(0).ColumnName
        Me.AssignedListBox.DataSource = ds.Tables("KSGroups")
        cn.Close()

Here is the complete error message

System.Data.OleDb.OleDbException was unhandled
  ErrorCode=-2147217904
  Message="Parameter [ ] has no default value."
  Source="Microsoft JET Database Engine"
  StackTrace:
       at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
       at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
       at Hasbara.frmKS_KSGAssignments.frmKS_KSGAssignments_Load(Object sender, EventArgs e) in C:\vs2005Projects\Hasbara\Hasbara\KS_KSGAssignments.vb:line 29
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.set_Visible(Boolean value)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Hasbara.frmKS_KSGAssignments.Main() in C:\vs2005Projects\Hasbara\Hasbara\KS_KSGAssignments.Designer.vb:line 2
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()



Answer this question

Why do I get Parameter ? has no default value

  • dlevine

    I am getting the same problem. I am trying to update a database through the BindingSource and TableAdapter and it is throwing this error. I have done some research online and in VB6 a possible problem was that the information being saved was in string format when the database expected integer.

    Currently, my database is set up as integers. Each bound data field is set up as integer. As i debug and watch all of the text boxes they all show up as string even though they are not defined as such. I have also read that all user entered text fields are string datatype.

    The catch is that it is only complaining about this ONE update. I have done the same thing in 3 other forms using the same code and nothing has come up. This table is a child table and is based on a 1 to many relationship. The table that is in question is the many side of the relationship, so there is no unique index.

    As soon as Me.TableAdapter.Update(Me.ALTDBDataSet) is called the program errors out. This is on an update routine. The add routine works fine by assigning the texbox strings to the integer database fields, but the update is having issues. Information on this problem is scarse and i am at my wits end trying to come up with a solution.

  • Peppi

    Hi,

    Could you provide the Error that your app is producing Also if you can, provide us with your UPDATE statement in your TableAdapter.UpdateCommand property....

    cheers,

    Paul June A. Domag



  • StLuisRey

    By enclosing the in [], you are instructing the database engine to treat it as a literal , rather than as a parameter placeholder. Try changing:

    ((KeywordSets.ID)=[ ])

    to

    (KeywordSets.ID = )


  • jrv1211

    James, your answer produced the same error.  However, thanks for trying.

    Paul, worked perfectly.  Now let's see if I can generalize it.  Keep tuned for alerts, in case I have a problem.

    Thank you again.

    dennist

    edit:  it was easy to generalize

  • Poojac25

    I was able to remedy the problem.

    I opened up the DataSet Designer and clicked on the appropriate table. I then went into the properties and changed the SQL that was automatically generated so that it would fit my needs. The problem was as i was passing the variables to write to the database, i was not passing all the variables that the SQL intended hence the reason for the Parameter no default value. The only issue i now have with VB is that whenever i change the names/fields of the table and am forced to reload it, it also erases and restores the default ADD/UPDATE/DELETE settings. It quickly becomes a pain when you are writing 5 things to a database through a join/update query.

  • Jim Andre Andersen

    Hi,

    I guess you can override that by specifying your ADD/EDIT/DELETE sql routines through code instead on the IDE. You can modify your Select/Update/Delete command before you use your table/data adapter objects.

    cheers,

    Paul June A. Domag



  • John Smallberries

    Hi,

    Try changing your Parameters.Add function to this:

    da.SelectCommand.Parameters.Add(new OleDbParameter("@ID", ID))

     

    cheers,

    Paul June A. Domag



  • Lutz Albers

    I should have read more closely. Good catch, Paul!

    BTW - It seems that Access doesn't mind the [ ] syntax, but SQL Server interprets [ ] as a column named " ". Better to use the bare syntax since most, if not all, RDBMs will understand it.

  • Why do I get Parameter ? has no default value