?
Solved

SQL in a DataGridView

Posted on 2007-10-10
5
Medium Priority
?
150 Views
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?
0
Comment
Question by:bdb12
  • 2
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
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...
0
 

Author Comment

by:bdb12
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
0
 
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
like
datagridview.datasource... = dataset.ta.fill(txtID.Text)
0
 

Author Comment

by:bdb12
ID: 20054805
Ok Im properly confused now...

What way were you describing? seems easier
0
 
LVL 26

Assisted Solution

by:EDDYKT
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 & "'"
0

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