الجزء الثانى
1 - جملة الاتصال
CODE
Private DbCommand As String = ""
Private bindingSrc As BindingSource
Private DbName As String = "auditor_db.db"
Private DbPath As String = Application.StartupPath & "\" & DbName
Private ConnString As String = "Data Source =" & DbPath & ";Version=3"
Private Connection As New SQLiteConnection(ConnString)
Private Command As New SQLiteCommand("", Connection)
Dim Pos As Point
2- كود ادخال البيانات الى قاعدة البينات
CODE
Private Sub InsertData()
Connection.Open()
If Connection.State = ConnectionState.Open Then
Command.Connection = Connection
Command.CommandText = "insert into user (
user_name,
user_password,
user_role )
Values
(
'" & TextBox1.Text & "',
'" & TextBox2.Text & "',
'" & ComboBox1.Text & "' ) "
Command.ExecuteNonQuery()
End If
Connection.Close()
End Sub
3 - كود اظهار البيانات فى الداتا جريد فيو
CODE
Private Sub ShowDataGridView()
DataGridView1.Rows.Clear()
Connection.Open()
If Connection.State = ConnectionState.Open Then
Command.Connection = Connection
Command.CommandText = "Select * from user"
Dim reader As SQLiteDataReader = Command.ExecuteReader
Using reader
While (reader.Read())
Me.DataGridView1.Rows.Add(reader.GetInt32(0),
reader.GetString(1),
reader.GetString(2),
reader.GetString(3))
End While
End Using
End If
Connection.Close()
End Sub
4 - كود استخراج البيانات من الداتا جريد فيو
CODE
Private Sub FromDataGridView()
Dim iRowIndex As Integer
For i As Integer = 0 To DataGridView1.SelectedCells.Count - 1
iRowIndex = DataGridView1.SelectedCells.Item(i).RowIndex
tbx0.Text = DataGridView1.Rows(iRowIndex).Cells(0).Value
TextBox1.Text = DataGridView1.Rows(iRowIndex).Cells(1).Value
TextBox2.Text = DataGridView1.Rows(iRowIndex).Cells(2).Value
ComboBox1.Text = DataGridView1.Rows(iRowIndex).Cells(3).Value
Next
End Sub
5 - كود تعديل البيانات فى قاعدة البينات
CODE
Private Sub UpdateData()
Connection.Open()
If Connection.State = ConnectionState.Open Then
Command.Connection = Connection
Command.CommandText = "Update user Set
user_name='" & TextBox1.Text & "',
user_password = '" & TextBox2.Text & "',
user_role = '" & ComboBox1.Text & "'
Where user_id ='" & tbx0.Text & "'"
Command.ExecuteNonQuery()
End If
Connection.Close()
End Sub
6 - كود حذف البيانات من قاعدة البيانات
CODE
Private Sub DeleteData()
Dim result1 As DialogResult = MessageBox.Show("هل تريد حقا حذف هذا المسئول ؟ ", "حذف مسئول", MessageBoxButtons.YesNo)
If result1 = DialogResult.Yes Then
Connection.Open()
If Connection.State = ConnectionState.Open Then
Command.Connection = Connection
Command.CommandText = "Delete From user Where user_id ='" & tbx0.Text & "'"
Command.ExecuteNonQuery()
End If
End If
Connection.Close()
End Sub