I have VB.Net Exp 2008 with SQL Exp 2008, on a windows form I have 6 databound textboxes and 6 unbound textboxes, in the bound textboxes the records show as the bound dataGridView rows are selected, in the unbound textboxes is where I will enter the new record to be sent to the database. Added an SQL database in the designer which gave me a dataset(MdDB1DataSet) and a tableAdapter(MdTBTableAdapter). My problem is with adding, updating and deleting records. The add records button addes it during debug to the dataGridView, but does not return when I debug again. So this means it is not added to the database. The update button updates the fields in the DGV, but no record was retained. Thanks for the help...
Add Record button:
Dim nr As DataRow = MdDB1DataSet.Tables(mdTb).NewRow nr(0) = Trim(txtAdd1.Text) nr(1) = Trim(txtAdd2.Text) nr(2) = Trim(txtAdd3.Text) nr(3) = Trim(txtAdd4.Text) nr(4) = Trim(txtAdd5.Text) nr(5) = Trim(txtAdd6.Text) MdDB1DataSet.Tables(mdTb).Rows.Add(nr) MdDB1DataSet.Tables(mdTb).AcceptChanges() MdTBTableAdapter.Update(MdDB1DataSet)
Update Record button:
Dim index As Integer
For index = 0 To dgvMM_Db.Rows.Count - 1
If dgvMM_Db.Rows(index).Selected = True Then
MsgBox(" Row # = " & index.ToString)
MdDB1DataSet.Tables(mdTb).Rows(index).Item(0) = Trim(txt1.Text)
MdDB1DataSet.Tables(mdTb).Rows(index).Item(1) = Trim(txt2.Text)
MdDB1DataSet.Tables(mdTb).Rows(index).Item(2) = Trim(txt3.Text)
MdDB1DataSet.Tables(mdTb).Rows(index).Item(3) = Trim(txt4.Text)
MdDB1DataSet.Tables(mdTb).Rows(index).Item(4) = Trim(txt5.Text)
MdDB1DataSet.Tables(mdTb).Rows(index).Item(5) = Trim(txt6.Text)
MdDB1DataSet.Tables(mdTb).AcceptChanges()
MdTBTableAdapter.Update(MdDB1DataSet.Tables(mdTb))
End If
Next

New Topic/Question
Reply



MultiQuote






|