parameter for sql query

Imports System.Data.SqlClient
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim vuser As String = InputBox("Enter user name")
        Dim connectionString As String = "Data Source=DOVHP\SQLEXPRESS;Initial Catalog=mala2;Integrated Security=True;Pooling=False"
        ' Dim sql As String = "SELECT * FROM tbusuario where login like 'sousa'"
        Dim sql As String = "SELECT * FROM tbusuario where login like" & vuser

        Dim connection As New SqlConnection(connectionString)
        Dim dataadapter As New SqlDataAdapter(sql, connection)
        Dim ds As New DataSet()

        dataadapter.Fill(ds, "usuario_table")
        connection.Close()
        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "usuario_table"
    End Sub
End Class

Open in new window


Hi,
I  want to populate the DataGridView with the register(s) where the login name is the one entered into the inputBox - vuser
There should be here a parameter which I don't know how to include.
*********************
Thanks
Dov Kruman
dovk179Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Hi Dov

Try something Like This....

 Imports System.Data.SqlClient
  Public Class Form1

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ds As New DataSet
        Dim vuser As String = InputBox("Enter user name")
        Dim connectionString As String = "Data Source=DOVHP\SQLEXPRESS;Initial Catalog=mala2;Integrated Security=True;Pooling=False"

        Dim sql As String = "SELECT * FROM tbusuario WHERE login LIKE '%' + @SUser + '%'"
        Dim SqlCon As New SqlConnection(connectionString)

        Dim Command As New SqlCommand(sql, SqlCon)
        Dim UserParam As New SqlParameter("@SUser", vuser)
        Command.Parameters.Add(AddressParam)

        Dim adapter As New SqlDataAdapter

        adapter.SelectCommand = Command
        adapter.Fill(ds)

        Me.DataGridView1.DataSource = ds.Tables(0)

End Sub
End Class

Open in new window


Hope It Helps

Yiannis
0
dovk179Author Commented:
Thanks Yiannis
I have a problem with line 14.
Name 'addressParam; is not declared!
any suggestion?

Dov
0
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Very Sorry my mistake. .change addressparam with userparam..

Yiannis
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dovk179Author Commented:
Working thanks a lot
Dov
0
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Glad to help Dov

Yiannis
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.