Could somebody help me out.
I'm trying to add some values from a textbox into my database
and so far i couldn't get it to work.
Printable View
Could somebody help me out.
I'm trying to add some values from a textbox into my database
and so far i couldn't get it to work.
Posting a sample app for you but I need to trim down the database size so it's under 100k, just a minute. :)
Actually that's a crappy example, let me put together a better one. Just a bit :)
:o can't get my example to work either :/ Looks really simple, doesn't error, but records never get written to the file.
Maybe some brighter soul will enlighten us both.Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objRow As DataRow = DataSet11.Table1.NewRow()
objRow("Text") = TextBox1.Text
DataSet11.AcceptChanges()
OleDbConnection1.Open()
Try
OleDbDataAdapter1.Update(DataSet11.Table1)
Catch ex As Exception
MsgBox(ex.Message)
Finally
OleDbConnection1.Close()
End Try
End Sub
AcceptChanges doesn't do what you think. You call it after the changes have been made (kind of like setting the IsDirty flag to False) or you don't have to do it at all. But if you call it before it thinks the changes have already been made and doesn't update.
Duh! Forgot to .Rows.Add!!
*bangs forehead against the wall* Although you're right Edneeis, AcceptChanges does keep the update from happening if you do it first. I guess the "correct" way would be:Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objRow As DataRow = DataSet11.Table1.NewRow()
objRow("Text") = TextBox1.Text
DataSet11.Table1.Rows.Add(objRow)
OleDbDataAdapter1.Update(DataSet11)
End Sub
Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objRow As DataRow = DataSet11.Table1.NewRow()
objRow("Text") = TextBox1.Text
DataSet11.Table1.Rows.Add(objRow)
Try
OleDbDataAdapter1.Update(DataSet11)
DataSet11.AcceptChanges()
Catch ex As Exception
msgbox(ex.Message)
End Try
End Sub
actually the code above wont work unless the data objects you are referencing are design time bound to your database
If you are trying to create the connection through code you should use OLEDB and either Use the OLEDBCommands specifiying each sql statement in code, or you can create a dataset via code and create an instance of an OLEDBDataadapter bind to the dataadapter an Instance of the OLEDBCommandBuilder, you still have to mainly specify the sql Select statement for the dataadapter but basically the builder will dynamically take care of the rest for you.
Yep that's the way I did it.Quote:
Originally posted by rudvs2
actually the code above wont work unless the data objects you are referencing are design time bound to your database