how to lookup table?

seahck

Member
Joined
Jul 12, 2004
Messages
6
Programming Experience
Beginner
im a newbie and i have some question.
how to lookup a table from a form. during form_load i want to lookup a field from a table to fill inside 1 of the textbox in the form. anyone know it? thank.........
 

ayan

Member
Joined
Jun 9, 2004
Messages
18
Programming Experience
Beginner
this?
VB.NET:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 	  Dim cn As New SqlConnection()
 	  cn.ConnectionString = "user id=sa;password=password;initial catalog=northwind;"
 	  cn.Open()
 
 	  Dim cmdtext As String = "select categoryname from categories where categoryid=1"
 	  Dim cm As New SqlCommand(cmdtext, cn)
 	  Dim dr As SqlDataReader = cm.ExecuteReader
 	  If dr.Read Then
 		 TextBox1.Text = dr(0)
 	  End If
 	  dr.Close()
 	  cn.Close()
    End Sub
 
Top Bottom