SQL in a DataGridView

Posted on 2007-10-10
Medium Priority
Last Modified: 2012-06-21
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?
Question by:bdb12
  • 2
  • 2
LVL 14

Accepted Solution

Jai S earned 1600 total points
ID: 20054620
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...

Author Comment

ID: 20054640
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
LVL 14

Assisted Solution

by:Jai S
Jai S earned 1600 total points
ID: 20054665
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
datagridview.datasource... = dataset.ta.fill(txtID.Text)

Author Comment

ID: 20054805
Ok Im properly confused now...

What way were you describing? seems easier
LVL 26

Assisted Solution

EDDYKT earned 400 total points
ID: 20055818
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 & "'"

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question