|
-
Sep 14th, 2003, 05:23 PM
#1
Thread Starter
Addicted Member
How to "expand" the INSERT command?
I'm using the INSERT command do add records to my database.
The problem is that I'm getting an error and I can't know where is it from becouse my database has many fields.
VB Code:
Dim myCommand As OleDb.OleDbCommand
myCommand.CommandText = "INSERT INTO myTable (myField1,myField2,myField3,myField4,myField5) VALUES ('" & _
TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" TextBox4.Text & "','" & TextBox5.Text & "')"
myCommand.ExecuteNonQuery()
Is there another way to add records?
-
Sep 14th, 2003, 07:09 PM
#2
Sleep mode
Yes , use Row obj as follow :
VB Code:
Public Overloads Sub SaveDB(ByVal TableStr As String)
Dim SQLStr = "SELECT * FROM " & TableStr
Dim MyAdapter As New OleDb.OleDbDataAdapter(SQLStr, MyConnection)
Dim builder As New OleDbCommandBuilder(MyAdapter)
Dim mydataset As New DataSet
MyAdapter.Fill(mydataset, TableStr)
Dim MyDataRow As DataRow = mydataset.Tables(TableStr).NewRow
'Change these colums to adapt yours .
MyDataRow("Column1") = "Value1"
MyDataRow("Column2") = "Value2"
MyDataRow("Column3") = "Value3"
MyDataRow("Column4") = "Value4"
mydataset.Tables(TableStr).Rows.Add(MyDataRow)
MyAdapter.Update(mydataset, TableStr)
MyAdapter = Nothing
MessageBox.Show("Data Saved..")
End Sub
-
Sep 15th, 2003, 06:05 AM
#3
Thread Starter
Addicted Member
Thanks.
I was using a code just like yours but I was getting sobre problems when update a record. So I decided to use just INSERT and UPDATE commands.
Do you have an example to update a record?
Thank you.
-
Sep 15th, 2003, 07:30 AM
#4
Sleep mode
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|