Querying data using .net (VB/C#)

First thing is to get the connection string and your database name (catalog in mssql).

Then, here is the VB code to get you going all the way of getting a record:

 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        myconnection = New SqlConnection(GetConnectionString)
        Dim command As New SqlClient.SqlCommand("select  first_name from users_tbl")
        Dim read As SqlClient.SqlDataReader = command.ExecuteReader()
        Dim name As String = read.GetString(0)
        TextBox1.Text = name

    End Sub

I put this in a button handler where the project only has this button and a text box for an output.



Leave a Reply

You must be logged in to post a comment.