הוספת רשומה חדשה לDB.

israel4ever

New member
הוספת רשומה חדשה לDB.

כתבתי את הקוד הבא שצריך לקבל מהמשתמש פקטים ולהוסיף אותם אל הבסיס נתונים. נשמע פשוט אבל משהו פה לא פועל כהלכה. הוא לא מודיע לי על שגיאה אבל עם זה הוא לא מבצע את ההוספת נתונים. זה הקוד:
Private Sub SaveData_Routine() Dim ConnectionString As String Dim oCon As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\No1Live4Ever\My Documents\Visual Studio Projects\Fill Details Using ADO.NET\db.mdb") Try oCon.Open() If oCon.State = ConnectionState.Open Then Dim sSQL As String = "SELECT * FROM Details" Dim oAdapter As New OleDb.OleDbDataAdapter(sSQL, oCon) Dim DS As New DataSet("Details") oAdapter.Fill(DS, "Details") oCon.Close() Dim oTable As DataTable oTable = DS.Tables("Details") Dim oRow As DataRow oRow = oTable.NewRow oRow("sFirstName") = txtFirstName.Text.Trim oRow("sSecondName") = txtSecondName.Text.Trim oRow("sCountry") = txtCountry.Text.Trim oRow("sCity") = txtCity.Text.Trim oRow("sPhone1") = txtPhone1.Text.Trim oRow("sPhone2") = txtPhone2.Text.Trim If OptionClient.Checked = True Then oRow("bClient") = True Else oRow("bClient") = False End If oTable.Rows.Add(oRow) DataGrid.DataSource = DS oCon.Open() Dim cmd As New OleDb.OleDbCommand(sSQL, oCon) oAdapter.InsertCommand = cmd oAdapter.Update(DS, "Details") End If Catch ex As Exception MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) Finally oCon.Close() End Try End Sub​
כמו שצינתי למעלה, אין הודעת שגיאה, אבל עם זאת ההוספת הנתונים לא מתבצעת. למישהו יש רעיון מדוע הבעיה הזו מתרחשת? דרך אגב, אם אתה\ את מכירה דרך טובה יותר להוספת נתונים לData base אין לי בעיה להשתמש בדרך שלך. תודה מראש.
 
למעלה