Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query

Status
Not open for further replies.

richself

Technical User
Jun 27, 2005
37
US
I have the following code for filling a DataGrid.

Dim myString As String = "SELECT * FROM Report WHERE ShiftID = 'Yellow'"
Dim myDA As OleDbDataAdapter
Dim myDS As New DataSet

myDA = New OleDbDataAdapter(myString, OleDbConnection1)

myDA.Fill(myDS)
DataGrid1.DataSource = (myDS)

it works fine. What I would like to do is have the user fill in a text box and be able to replace 'Yellow' with a shift of thier choice. I tried

Dim mySearch as String
mySearch = shiftTextBox.text

Then replacing the 'Yellow' in the first code with 'mySearch'. It returns nothing however. Any ideas?
 
Hi
As I understand from your statement Your are modifying the string with the SQL query. I won't work that way. You should make parametrized query and set the parameter
something like that:
sql text:
<code>
SELECT * FROM Report WHERE ShiftID = ?
</code>
The code should be like this
<code>
Dim cmd as new OleDbCommand (strSQL,connectionV)
cmd.Parameters.Add ("param",OleDbType.WChar, 30)
cmd.Parameters(0).Value = "blue"
Dim rdr As OleDbDataReader = cmd.ExecuteReader()
</code>
I hope it will help you!
Lyubomyr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top