Anda di halaman 1dari 6

General Declarations Imports System.Data.Sql Imports System.Data.Sqlclient Partial Class BranchMast Inherits System.Web.UI.

Page Add Button Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As New System.Data.SqlClient.SqlConnection con.ConnectionString = "dsn=oracledsn;uid=scott;pwd=tiger;" Dim myCommand As New System.Data.SqlClient.SqlCommand myCommand.CommandText = "insert into BMast values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "')" myCommand.Connection = con con.Open() myCommand.ExecuteNonQuery() Call datcombo() MsgBox("Branch DetailsRetrieved", MsgBoxStyle.Exclamation, "Packing") con.Close() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox1.Focus() End Sub Update Button Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Dim con As New System.Data.SqlClient.SqlConnection con.ConnectionString = "dsn=oracledsn;uid=scott;pwd=tiger; Dim myCommand As New System.Data.SqlClient.SqlCommand

myCommand.CommandText = "update BMast set Bname ='" & TextBox2.Text & " ',Badd= '" & TextBox3.Text & "', Phone= '" & TextBox4.Text & "', email= '" & TextBox5.Text & "' myCommand.Connection = con con.Open() myCommand.ExecuteNonQuery() MsgBox("Branch DetailsUpdated", MsgBoxStyle.Exclamation, "Packing") con.Close() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox1.Focus() End Sub Clear Button Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox1.Focus() Call autogen() End Sub Delete Button Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click Dim con As New System.Data.SqlClient.SqlConnection con.ConnectionString = "dsn=oracledsn;uid=scott;pwd=tiger;" Dim myCommand As New System.Data.SqlClient.SqlCommand myCommand.CommandText = "Delete FROM BMast where Pacode= '" & TextBox1.Text & "' " myCommand.Connection = con con.Open()

myCommand.ExecuteNonQuery() Call datcombo() MsgBox("Branch DetailsDeleted", MsgBoxStyle.Exclamation, "Packing") con.Close() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox7.Text = "" TextBox8.Text = "" TextBox9.Text = "" TextBox1.Focus() End Sub Search Grid Coding Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click Dim con As New System.Data.SqlClient.SqlConnection con.ConnectionString = "dsn=oracledsn;uid=scott;pwd=tiger;" Dim myCommand As New System.Data.SqlClient.SqlCommand myCommand.CommandText = "Select * from BMast" myCommand.Connection = con con.Open() myCommand.ExecuteNonQuery() Dim Rdr1 As SqlDataReader Rdr1 = myCommand.ExecuteReader GridView1.DataSource = Rdr1 GridView1.DataBind() Rdr1.Close() con.Close() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox1.Focus() End Sub

Autogenration Function Public Sub autogen() Dim strConn As String = "dsn=oracledsn;uid=scott;pwd=tiger; Dim Conn1 As SqlConnection Dim Cmd1 As SqlCommand Dim strSQL As String Dim sno As Integer = 0 Conn1 = New SqlConnection(strConn) Conn1.Open() strSQL = "SELECT Count(*) FROM BMast" Cmd1 = New SqlCommand(strSQL, Conn1) Dim RecordCount As Integer = Cmd1.ExecuteScalar() If RecordCount = 0 Then MsgBox("No Records") TextBox1.Text = "PK001" Else TextBox1.Text = "PK00" & RecordCount + 1 End If Conn1.Close() End Sub Page Section Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim strConn As String = "dsn=oracledsn;uid=scott;pwd=tiger;" Dim Conn1 As SqlConnection Dim Cmd1 As SqlCommand Dim strSQL As String Dim sno As Integer = 0 Dim reader As SqlDataReader If Not Page.IsPostBack Then DropDownList1.Items.Clear() DropDownList1.Items.Add("[Select]") strSQL = "Select Pacode from BMast" Conn1 = New SqlConnection(strConn) Conn1.Open() Cmd1 = New SqlCommand(strSQL, Conn1) reader = Cmd1.ExecuteReader While reader.Read DropDownList1.Items.Add(reader("Pacode"))

End While Conn1.Close() Cmd1.Dispose() Conn1.Dispose() reader.Close() End If Call autogen() End Sub Search Button Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click Try Dim strConn As String = "dsn=oracledsn;uid=scott;pwd=tiger;" Dim Conn1 As SqlConnection Dim Cmd1 As SqlCommand Dim strSQL As String Dim sno As Integer = 0 Dim reader As SqlDataReader Conn1 = New SqlConnection(strConn) Conn1.Open() strSQL = "Select * from BMast where Pacode ='" & (Trim(DropDownList1.SelectedItem.Text)) & "'" Cmd1 = New SqlCommand(strSQL, Conn1) reader = Cmd1.ExecuteReader If reader.Read Then TextBox1.Text = reader.Item(0) TextBox2.Text = reader.Item(1) TextBox3.Text = reader.Item(2) TextBox4.Text = reader.Item(3) TextBox5.Text = reader.Item(4) End If Conn1.Close() Cmd1.Dispose() Conn1.Dispose() reader.Close() Catch ex As Exception lblerror.Text = ex.Message End Try End Sub

DataCombo Update Function Public Sub datcombo() Dim strConn As String = "Integrated Security=SSPI;Server=Spark;Database=Cargo;" Dim Conn1 As SqlConnection Dim Cmd1 As SqlCommand Dim strSQL As String Dim sno As Integer = 0 Dim reader As SqlDataReader DropDownList1.Items.Clear() DropDownList1.Items.Add("[Select]") strSQL = "Select Pacode from BMast" Conn1 = New SqlConnection(strConn) Conn1.Open() Cmd1 = New SqlCommand(strSQL, Conn1) reader = Cmd1.ExecuteReader While reader.Read DropDownList1.Items.Add(reader("Pacode")) End While End Sub End Class

Anda mungkin juga menyukai