06-08-14, 12:56 AM
عندي مشكلة في كود زر التحديث عند الامر ExecuteNonQuery()
هذا شكل الفورم
http://vb4arb.com/vb/gallery/3937_05_08_14_2_48_29.png
وهذا كود الفورم بالكامل
////////////////////////////////
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim DSProvider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\PC1\Documents\Visual Studio 2013\Projects\Ado totural\Ado totural\bin\Debug\MBase.accdb"
Dim con As New OleDbConnection(DSProvider)
Dim cmd As String = "SELECT Id,Name,City,Tel,Country from Info order by ID"
Dim DataS As New DataSet
Dim DataA As New OleDbDataAdapter(cmd, con)
Dim AddC As New OleDbCommand
Sub AddF()
con.Open()
AddC.ExecuteNonQuery()
DataS.Clear()
DataA.Fill(DataS, "Info")
con.Close()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con.Open()
DataA.Fill(DataS, "Info")
con.Close()
LabelID.DataBindings.Add("text", DataS, "Info.ID")
TextBox2.DataBindings.Add("text", DataS, "Info.Name")
TextBox3.DataBindings.Add("text", DataS, "Info.city")
TextBox4.DataBindings.Add("text", DataS, "Info.Tel")
TextBox5.DataBindings.Add("text", DataS, "Info.Country")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
BindingContext(DataS, "info").Position = 0
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
BindingContext(DataS, "Info").Position += 1
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
BindingContext(DataS, "Info").Position -= 1
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
BindingContext(DataS, "Info").Position = BindingContext(DataS, "Info").Count - 1
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
LabelID.Text = vbNullString
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox2.Focus()
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
AddC.Connection = con
AddC.CommandType = CommandType.Text
AddC.CommandText = "insert into Info(ID,Name,City,Tel,Country) values('" & LabelID.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "')"
AddF()
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
con.Open()
DataS.Clear()
DataA.Fill(DataS, "Info")
con.Close()
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If MsgBox("هل تريد حذف السجل", MsgBoxStyle.OkCancel) = MsgBoxResult.Cancel Then
Exit Sub
End If
AddC.Connection = con
AddC.CommandType = CommandType.Text
AddC.CommandText = " delete from Info where id ='" & LabelID.Text & "' "
AddF()
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
AddC.Connection = con
AddC.CommandType = CommandType.Text
AddC.CommandText = "update Info set Name ='" & TextBox2.Text & "', City ='" & TextBox3.Text & "', Tel ='" & TextBox4.Text & "', Countery ='" & TextBox5.Text & "' where id= '" & LabelID.Text & "'"
AddF()
End Sub
End Class
وقاعدة البيانات مرفقة
هذا شكل الفورم
http://vb4arb.com/vb/gallery/3937_05_08_14_2_48_29.png
وهذا كود الفورم بالكامل
////////////////////////////////
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim DSProvider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\PC1\Documents\Visual Studio 2013\Projects\Ado totural\Ado totural\bin\Debug\MBase.accdb"
Dim con As New OleDbConnection(DSProvider)
Dim cmd As String = "SELECT Id,Name,City,Tel,Country from Info order by ID"
Dim DataS As New DataSet
Dim DataA As New OleDbDataAdapter(cmd, con)
Dim AddC As New OleDbCommand
Sub AddF()
con.Open()
AddC.ExecuteNonQuery()
DataS.Clear()
DataA.Fill(DataS, "Info")
con.Close()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con.Open()
DataA.Fill(DataS, "Info")
con.Close()
LabelID.DataBindings.Add("text", DataS, "Info.ID")
TextBox2.DataBindings.Add("text", DataS, "Info.Name")
TextBox3.DataBindings.Add("text", DataS, "Info.city")
TextBox4.DataBindings.Add("text", DataS, "Info.Tel")
TextBox5.DataBindings.Add("text", DataS, "Info.Country")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
BindingContext(DataS, "info").Position = 0
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
BindingContext(DataS, "Info").Position += 1
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
BindingContext(DataS, "Info").Position -= 1
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
BindingContext(DataS, "Info").Position = BindingContext(DataS, "Info").Count - 1
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
LabelID.Text = vbNullString
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox2.Focus()
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
AddC.Connection = con
AddC.CommandType = CommandType.Text
AddC.CommandText = "insert into Info(ID,Name,City,Tel,Country) values('" & LabelID.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "')"
AddF()
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
con.Open()
DataS.Clear()
DataA.Fill(DataS, "Info")
con.Close()
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If MsgBox("هل تريد حذف السجل", MsgBoxStyle.OkCancel) = MsgBoxResult.Cancel Then
Exit Sub
End If
AddC.Connection = con
AddC.CommandType = CommandType.Text
AddC.CommandText = " delete from Info where id ='" & LabelID.Text & "' "
AddF()
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
AddC.Connection = con
AddC.CommandType = CommandType.Text
AddC.CommandText = "update Info set Name ='" & TextBox2.Text & "', City ='" & TextBox3.Text & "', Tel ='" & TextBox4.Text & "', Countery ='" & TextBox5.Text & "' where id= '" & LabelID.Text & "'"
AddF()
End Sub
End Class
وقاعدة البيانات مرفقة