'------------------------Select With DataSet Vb Code---------------------------'
Dim StrSQL as string = "Select * From TableName"
Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;")
If cn.State = ConnectionState.Closed Then cn.Open()
Dim da As New SqlDataAdapter(StrSQL, cn)
Dim ds As New DataSet
da.Fill(ds,"TableName")
If cn.State = ConnectionState.Open Then cn.Close()
'------------------------Select With DataTable Vb Code---------------------------'
Dim StrSQL as string = "Select * From TableName"
Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename="& Application.StartupPath &"\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;")
If cn.State = ConnectionState.Closed Then cn.Open()
Dim da As New SqlDataAdapter(StrSQL, cn)
Dim dt As New DataTable
da.Fill(dt)
If cn.State = ConnectionState.Open Then cn.Close()
'------------------------INSERT With DataTable Vb Code---------------------------'
Dim StrSQL as string = "INSERT INTO Castomer (ID,Castomer_Name,Castomer_Tel,Castomer_Mobaile,Castomer_Note ) VALUES ('" & Txt_ID.Text & "','" & Txt_Castomer_Name.Text & "','" & Txt_Castomer_Tel.Text & "','" & Txt_Castomer_Mobaile.Text & "','" & Txt_Castomer_Note.Text & "')"
Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename="& Application.StartupPath &"\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;")
If cn.State = ConnectionState.Closed Then cn.Open()
Dim da As New SqlDataAdapter(StrSQL, cn)
Dim dt As New DataTable
da.Fill(dt)
If cn.State = ConnectionState.Open Then cn.Close()
'------------------------Update With DataTable Vb Code---------------------------'
Dim StrSQL as string = "UPDATE Castomer SET Castomer_Name='" & Txt_Castomer_Name.Text & "', Castomer_Tel='" & Txt_Castomer_Tel.Text & "', Castomer_Mobaile='" & Txt_Castomer_Mobaile.Text & "', Castomer_Note='" & Txt_Castomer_Note.Text & "' Where ID='" & Txt_ID.Text & "'"
Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename="& Application.StartupPath &"\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;")
If cn.State = ConnectionState.Closed Then cn.Open()
Dim da As New SqlDataAdapter(StrSQL, cn)
Dim dt As New DataTable
da.Fill(dt)
If cn.State = ConnectionState.Open Then cn.Close()
'------------------------Delete With DataTable Vb Code---------------------------'
Dim StrSQL as string = "Delete From Castomer Where ID = '"& Txt_ID.Text & "'"
Dim TxtID As String =Txt_ID.Text
If MsgBox("هل أنت متأكد من حذف السجل المحدد " & Txt_ID.Text, MsgBoxStyle.YesNo + MsgBoxStyle.Question + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.MsgBoxRtlReading, "حذف سجل") = MsgBoxResult.Yes Then
Dim cn As New SqlConnection("Server=.\SQLExpress;AttachDbFilename="& Application.StartupPath &"\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;")
If cn.State = ConnectionState.Closed Then cn.Open()
Dim da As New SqlDataAdapter(StrSQL, cn)
Dim dt As New DataTable
da.Fill(dt)
If cn.State = ConnectionState.Open Then cn.Close()
MsgBox("تم حذف السجل المحدد "& Txt_ID.Text &" بنجاح ", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.MsgBoxRtlReading, "حذف سجل")
End If