Sunteți pe pagina 1din 3

Public Class Form1 Dim conn1 As New SqlConnection("Data Source=LAB126_1-PC;Initial Catalog=Adve ntureWorks;Integrated Security=True") ' Dim conn2 As New

SqlConnection("Data Source=MOH-PC\SQLS5;Initial Catalog=M K;Integrated Security=True") Dim comm1 As New SqlCommand 'Dim comm2 As New SqlCommand Dim dr As SqlDataReader Dim ds As New DataSet Dim da As New SqlDataAdapter("Select ContactId,Firstname,Lastname,EmailAddre ss,Phone from Person.Contact ", conn1) ' ' Dim da As New SqlDataAdapter("Select ContactId,Firstname,Lastname,EmailAdd ress,Phone from Person.Contact= ", =&textbox1.tex) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button1.Click Try conn1.Open() Dim s As String = "Select ContactId,Firstname,Lastname,EmailAddress, Phone from Person.Contact where ContactId=" & TextBox1.Text MsgBox(s) comm1.CommandText = s comm1.Connection = conn1 dr = comm1.ExecuteReader() getOne() Catch ex As Exception 'MsgBox(ex.Message) MsgBox("Error in DataBase") End Try End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button2.Click getOne() End Sub Private Sub getOne() If dr.Read() Then TextBox1.Text TextBox2.Text TextBox3.Text TextBox4.Text TextBox5.Text End If End Sub

= = = = =

dr(0) dr(1) dr(2) dr(3) dr(4)

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Wind ows.Forms.FormClosingEventArgs) Handles Me.FormClosing conn1.Close() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles MyBase.Load Button1.Enabled = False

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button5.Click Button1.Enabled = False Button6.Enabled = True Try conn1.Open() da.Fill(ds, "abc") Catch ex As Exception MsgBox(ex.Message) Finally conn1.Close() End Try End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button6.Click Dim drow As DataRow drow = ds.Tables("abc").Select("ContactId=" & TextBox1.Text)(0) ' drow = ds.Tables("abc").Select("ContactId=50)(0) If drow(0) <> 0 Then TextBox1.Text = drow.Item("ContactId") TextBox2.Text = drow("firstname") TextBox3.Text = drow(2) TextBox4.Text = drow(3) TextBox5.Text = drow(4) End If End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button7.Click Dim drow As DataRow Dim c As Integer = ds.Tables("abc").Select("ContactId<=" & TextBox1.Text ).Count If c <= 1 Then c = 2 End If drow = ds.Tables("abc").Select("ContactId<=" & TextBox1.Text)(c - 2) If drow(0) <> 0 Then TextBox1.Text TextBox2.Text TextBox3.Text TextBox4.Text TextBox5.Text End If End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button8.Click Dim drow As DataRow = = = = = drow.Item("ContactId") drow("firstname") drow(2) drow(3) drow(4)

Dim c As Integer = ds.Tables("abc").Select("ContactId>=" & TextBox1.Text ).Count If c > 1 Then drow = ds.Tables("abc").Select("ContactId>=" & TextBox1.Text)(1) If drow(0) <> 0 Then TextBox1.Text TextBox2.Text TextBox3.Text TextBox4.Text TextBox5.Text End If End If End Sub End Class = = = = = drow.Item("ContactId") drow("firstname") drow(2) drow(3) drow(4)

S-ar putea să vă placă și