SQL in a DataGridView

With my DataGridView, I'm having trouble trying to pass a textbox value to a query as one of the parameters

I use the following query

SELECT     *
FROM         Timesheet
WHERE     UserID = txtID.Text

At run time it throws up an error

'No value given for one or more parameters'

Any help?
bdb12Asked:
Who is Participating?
 
Jai SConnect With a Mentor Tech ArchCommented:
it has to be like this
"SELECT     *
FROM         Timesheet
WHERE     UserID = " + txtID.Text
txtID.Text is a parameter and it should not be a part of your QUERY...it has to contain the value and not the name of the control...
0
 
bdb12Author Commented:
Went to the Dataset, then Query Builder & changed the syntax to what u said.

'SELECT     *
FROM         Timesheet
WHERE     UserID = ' + txtID.[Text]

Still not working tho...

thanks for your reply
0
 
Jai SConnect With a Mentor Tech ArchCommented:
wrong method...

if you are using a DATASET to assign to datasource...you ahve to do it this way
SELECT     *
FROM         Timesheet
WHERE     UserID = @userid
when you specify this query...it will generate a function like FILL with a parameter...you can then use the method while setting the datasource to your datagridview
like
datagridview.datasource... = dataset.ta.fill(txtID.Text)
0
 
bdb12Author Commented:
Ok Im properly confused now...

What way were you describing? seems easier
0
 
EDDYKTConnect With a Mentor Commented:
if your userid is number

dim SQL as string

SQL = "SELECT  * FROM Timesheet WHERE UserID = " & val(txtID.Text)

if your userid is string


SQL = "SELECT  * FROM Timesheet WHERE UserID = '" & txtID.Text & "'"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.