|
-
Oct 1st, 2002, 12:10 AM
#1
Thread Starter
New Member
inserting into a access database
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.
-
Oct 1st, 2002, 01:29 AM
#2
Fanatic Member
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
Last edited by Slow_Learner; Oct 1st, 2002 at 01:32 AM.
-
Oct 1st, 2002, 02:33 AM
#3
Fanatic Member
can't get my example to work either :/ Looks really simple, doesn't error, but records never get written to the file.
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
Maybe some brighter soul will enlighten us both.
-
Oct 1st, 2002, 03:26 AM
#4
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.
-
Oct 1st, 2002, 01:44 PM
#5
Fanatic Member
Duh! Forgot to .Rows.Add!!
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
*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)
Try
OleDbDataAdapter1.Update(DataSet11)
DataSet11.AcceptChanges()
Catch ex As Exception
msgbox(ex.Message)
End Try
End Sub
-
Oct 1st, 2002, 09:58 PM
#6
Fanatic Member
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.
-
Oct 1st, 2002, 11:19 PM
#7
Fanatic Member
Originally posted by rudvs2
actually the code above wont work unless the data objects you are referencing are design time bound to your database
Yep that's the way I did it.
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
|