The OleDbCommand, in general but especially for JET, does not support named
parameters in the CommandText.
Instead parameters are positional and designated by ?.
So your CommandText then becomes:
"SELECT * from tblAssets where asset_tag=?"
The positional parameter is satisfied by the OleDbParameter in the relative
position in the Parameters collection so it is CRITICAL that they are added
in the correct sequence.
When you defined an OleDbCommand, you must give it a name, even though it is
is ignored.
So your parameter collection, is populated thus:
assCmd.Parameters.Add("asset_tag", OleDbType.VarChar).Value =
cboAsset.Text
Note that I have demonstrated using 'asset-tag' so that it becomes
self-documenting to a degree.
Also note that the Add method has a number of overloads that make defining
OleDBParameters easier.
In addition, you do not HAVE to define the width of the column in question.
If you omit the width then it will be inferred at execution-time.
IIRC there is also a method AddWithValue so that you can add an
OleDbParameter thus:
assCmd.Parameters.AddWithValue("asset_tag", cboAsset.Text)
In this case both the type and the with of the column in question are
inferred at execution-time.
"bill" <bill@bottlegarden.comwrote in message
news:u6U3Wgw6IHA.1192@TK2MSFTNGP05.phx.gbl...
Quote:
Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oled b.4.0;" &
"data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
2008\IT_Assets.mdb")
>
Dim dataAdapter As OleDb.OleDbDataAdapter
>
Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
asset_tag = @fn", Con)
>
assCmd.Parameters.Add(New OleDb.OleDbParameter("@fn",
OleDb.OleDbType.VarChar, 30)).Value = Me.cboAsset.Text
>
Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>
Dim DT As New DataTable
>
DataAdapter.Fill(DT)
>
DataAdapter.Dispose()
>
'I'm hoping that this recordset will populate the grid but nothing
happens?
>
Me.DataGridView1.DataSource = DT
>
>