Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a textbox, a datgrid and a button on my form.
I want to use the textbox.text entered by the user to fill the data grid when the user clicks the button.

I have tried to add the textbox.text in the sql WHERE clause but nothing happens:

VB
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Test_NAB_transDataSet.Split' table. You can move, or remove it, as needed.
        Me.SplitTableAdapter.Fill(Me.Test_NAB_transDataSet.Split)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.SplitTableAdapter.NABid(Me.Test_NAB_transDataSet.Split)
    End Sub
End Class


so... in the Query Builder I have the following:
SQL
SELECT        ID, NABTransID, Category, SubCategory, Amount
FROM            Split
WHERE        (NABTransID = '" + Me.TextBox1.Text + "')



thanks in advanced
Stephen
Posted
Updated 22-Apr-11 21:49pm
v2

1 solution

Without seeing you actual code, it is difficult to tell what the problem is. Since I don't know how you are filling your grid, I have to give you a concatenated solution:
string strSelect = "SELECT * FROM SplitTrans WHERE nabID='" + TextBox1.Text + "'";
However, you should use Parametrized queries instead, to avoid accidental or deliberate SQL Injection attack. We would need to see the relevant code fragment to tell you how to do that, though.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900