SelectCommand

adshocker

Well-known member
Joined
Jun 30, 2007
Messages
180
Programming Experience
Beginner
how do one use a selectcommand with parameters like for example i have an empty datagrid with columns of the table. then on column1 i enter a value that i want to search.

i tried

VB.NET:
Dim myAdapter as new OleDBDataAdapter
Dim cmSelect as new OleDBCommand("SELECT * FROM table1 WHERE column1 = :column1", myConnection)
Dim myDataSet as DataSet
myAdapter.SelectCommand = cmSelect
myAdapter.Fill(myDataSet, "table1")
myDataGrid.DataSource = myDataSet.Tables("table1")

i get an error here that says not all variables are bound.

any clues?

thanks.
 
VB.NET:
Dim myAdapter as new OleDBDataAdapter
Dim cmSelect as new OleDBCommand("SELECT * FROM table1 WHERE column1 = :[B]column1xyz[/B]", myConnection)
[COLOR="Blue"]cmSelect.Parameters.Add("[B]column1xyz[/B]", [B]OracleType.WhateverType[/B]).Value = [B]"Whatever Value"[/B][/COLOR]
Dim myDataSet as DataSet
myAdapter.SelectCommand = cmSelect
myAdapter.Fill(myDataSet, "table1")
myDataGrid.DataSource = myDataSet.Tables("table1")

See the blue line. Note the parameter name matches. Type must be a database type compatible with what you are setting as a value. If you are setting a date value, use e.g. OracleType.DateTime.
Why are you using OleDbAdapter when your use of : in the SQL parameter indicates you are using ORACLE ?
 
err.. sorry, i'm actually using OracleDataAdapter... just used OleDBDataAdapter as an example... forgot to change the parameter format. my bad.

but anyway, thanks for the info. works perfect. =)
 
Back
Top