You are on page 1of 2

Imports System.Data.

SqlClient Public Class Form1 Dim con As SqlConnection Dim com, com1 As SqlCommand Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click con = New SqlConnection com = New SqlCommand Dim rd As SqlDataReader con.ConnectionString = "Data Source=.;Initial Catalog=dev;Integrated Security=True" con.Open() com.CommandText = "select * from mohit" com.Connection = con rd = com.ExecuteReader While rd.Read If TextBox1.Text = rd(0).ToString Then TextBox2.Text = rd(1).ToString TextBox3.Text = rd(2).ToString TextBox4.Text = rd(3).ToString TextBox5.Text = rd(4).ToString TextBox6.Text = rd(5).ToString TextBox7.Text = rd(6).ToString TextBox8.Text = rd(7).ToString End If End While End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click con = New SqlConnection com = New SqlCommand com1 = New SqlCommand Dim rd As SqlDataReader

con.ConnectionString = "Data Source=.;Initial Catalog=dev;Integrated Security=True" con.Open() com.CommandText = "insert into mohit values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "')" com1.CommandText = "select * from mohit" com.Connection = con com1.Connection = con rd = com1.ExecuteReader While rd.Read If Val(TextBox1.Text) = rd(0) Then MsgBox("Roll number already exist") Exit Sub End If End While rd.Close() com.ExecuteNonQuery() MsgBox("insert") End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click con = New SqlConnection com = New SqlCommand con.ConnectionString = "Data Source=.;Initial Catalog=dev;Integrated Security=True" con.Open() com.CommandText = "update mohit set name='" & TextBox2.Text & "',m1='" & TextBox3.Text & "',m2='" & TextBox4.Text & "',m3='" & TextBox5.Text & "',tot='" & TextBox6.Text & "',avgerage='" & TextBox7.Text & "',result='" & TextBox8.Text & "' where rno='" & TextBox1.Text & "'" com.Connection = con com.ExecuteNonQuery() MsgBox("update") End Sub End Class

You might also like