Hello,
How to add a new record to Access database using dataset and table? I have in mind something like this code below (that raises error) but I don't want to use any SQL. Simple like this:
1. set connection to database and open it
2. Select right dataset table in the database and add a new row to it using NewRow command.
Can someone show me an example how to do it without using SQL and fill the dataset first with select command? Is it possible? I'm using VWD 2008.
Dim conn As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;UserID=administrator;Passwo rd=palani;Trusted_connection=yes;Initial Catalog=palani;Data Source=PALANI")
Dim da As New OleDb.OleDbDataAdapter()
Dim selcust As New OleDb.OleDbCommand("select * from customerdetails", conn)
Dim ds As New DataSet()
Dim dt As DataTable
Dim dr As DataRow
Dim flag As Integer
Private Sub cmdSAVE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)HandlescmdSAVE.Click
If flag = 1 Then
conn.Open()
dt = ds.Tables.Add("CustomerDetails")
dr = dt.NewRow()
dr(0) = CType(txtCustID.Text, Integer)----------------Here ERROR is Raised.
dr(1) = txtName.Text
dr(2) = txtAddress1.Text
dr(3) = txtAddress2.Text
dr(4) = txtCity.Text
dr(5) = CType(txtPhoneNO.Text, Integer)
dr(6) = CType(txtCellNo.Text, Integer)
dr(7) = txtMailID.Text
dt.Rows.Add(dr)
da.Update(ds, "customerdetails")
da.Fill(ds)
conn.Close()
End If