1 / 11

ສ້າງ DataBase ໃນ SQL Database name:KPIT , Table: TblStd

ສ້າງ DataBase ໃນ SQL Database name:KPIT , Table: TblStd. ສ້າງ Form ໃນ VB.Net.

beck
Download Presentation

ສ້າງ DataBase ໃນ SQL Database name:KPIT , Table: TblStd

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ສ້າງ DataBase ໃນ SQL • Database name:KPIT, Table: TblStd

  2. ສ້າງ Form ໃນVB.Net

  3. < %@ Import NameSpace="System.Data.SqlClient"%> < script language=“VB” runat="server"> Dim Cnn as SqlConnectionDim Cmm as SqlCommandDim StringConnection as StringDim StringCommand as StringSub Page_Load()If Not Page.IsPostBack() ThenCboSex.Items.Add("Male")CboSex.Items.Add("Female")End IfEnd Sub

  4. Sub BtnSave_Click(s as Object, e as EventArgs) StringConnection="Server=PrumMala;Database=KPIT;User ID=sa;Password=123" Cnn = New SqlConnection(StringConnection) Dim dg as New SqlDataAdapter("Select ID From TblStd where ID="& TxtID.text &"",Cnn) Dim ds as New Dataset dg.Fill(ds,"TblStd") If ds.Tables("TblStd").Rows.Count > 0 Then label2.text="ID is already input, Please Change ID" Else label2.text="" StringCommand="Insert Into TblStd(ID,Name,Sex,DOB,POB,Address,E_mail)" & _ "Values(@ID,@Eng_Name,@Sex,@DOB,@POB,@Address,@E_mail)"

  5. Cmm=New SqlCommand(StringCommand,Cnn) Cmm.Parameters.Add("@ID",TxtID.Text) Cmm.Parameters.Add("@Eng_Name",TxtEName.Text) Cmm.Parameters.Add("@Sex",CboSex.Text) Cmm.Parameters.Add("@DOB",TxtDOB.Text) Cmm.Parameters.Add("@POB",TxtPOB.Text) Cmm.Parameters.Add("@Address",TxtAddress.Text) Cmm.Parameters.Add("@E_mail",TxtEmail.Text) Cnn.Open() Cmm.ExecuteNonQuery() Cnn.Close() Call Clear() End If End Sub

  6. Sub BtnSearch_Click(s as Object, e as EventArgs) Label2.Text="" StringConnection="Server=PrumMala;Database=KPIT;User ID=sa;Password=123" Cnn = New SqlConnection(StringConnection) Dim Cmd as New SqlCommand(" Select * From TblStd " & _ " Where ID=" & TxtID.text & "",Cnn) Cnn.Open() Cmd.ExecuteNonQuery() Dim Rs as SqlDataReader Rs=Cmd.ExecuteReader

  7. Dim B as Integer Do While Rs.Read TxtEName.text=Rs.Item(1) CboSex.DataTextField=Rs.Item(2) TxtDOB.text=Rs.Item(3) TxtPOB.text=Rs.Item(4) TxtAddress.text=Rs.Item(5) TxtEmail.text=Rs.Item(6) B=1 Loop If B< > 1 then Label2.text="Data not found!" End If Cnn.Close() End Sub

  8. Sub BtnUpdate_Click(s as Object, e as EventArgs) StringConnection="Server=PrumMala;Database=KPIT;User ID=sa;Password=123" Cnn = New SqlConnection(StringConnection) Dim Cmd as new SqlCommand("Update TblStd Set " & _ " ID = " & TxtID.Text & _ ",Name=" & TxtEName.Text & _ ",Sex=" & CboSex.text & _ ",DOB="& TxtDOB.Text & _ ",POB=" & TxtPOB.Text & _ ",Address=" & TxtAddress.Text & _ ",E_mail=" & TxtEmail.text & _ " Where ID=" & TxtID.Text & "",Cnn) Cnn.Open() Cmd.ExecuteNonQuery() Cnn.Close() Call Clear() End Sub

  9. Sub BtnClear_Click(s as Object, e as EventArgs) Call Clear() End Sub Sub Clear() Me.TxtID.Text="" Me.TxtEName.Text="" Me.CboSex.ClearSelection() Me.TxtDOB.Text="" Me.TxtPOB.Text="" Me.TxtAddress.Text="" Me.TxtEmail.Text="" End Sub

  10. Add this code into your SAVE button code onclick=" BtnSave_Click" Add this code into your SEARCH button code onclick="BtnSearch_Click Add this code into your UPDATE button code onclick="BtnUpdate_Click" Add this code into your DELETE button code onclick="BtnDelete_Click" Add this code into your CLEAR button code onclick="BtnClear_Click"

More Related