SQL in a DataGridView

Posted on 2007-10-10
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
    LVL 14

    Accepted Solution

    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 has to contain the value and not the name of the control...

    Author Comment

    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

    wrong method...

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

    Author Comment

    Ok Im properly confused now...

    What way were you describing? seems easier
    LVL 26

    Assisted Solution

    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

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now