|
-
Jan 8th, 2003, 06:50 PM
#1
Thread Starter
New Member
adding a record to a dataset using ado.net
I have opened a connection to an OLEDB using the following code below. However, after the application that uses the dll I created is done running and I open the access database the table does not contain the data I added. Can anyone tell me why?
' Open a connection to the database.
Dim strConnection As String = "DataSource=C:\test.mdb;"
Dim cn As oledb.oledbconnection = new oledb.oledbconnection(strConnection)
cn.Open( )
' Set up a data set command object.
Dim strSelect As String = "SELECT * FROM Table"
Dim cmd As New oledb.oledbAdapter(strSelect, cn)
Dim ds As New DataSet( )
dscmd.Fill(ds, "Table")
dim dt as datatable()
Dim row As DataRow = dt.NewRow( )
row("ID") = 1
row("Description") = "Test 1"
dt.Rows.Add(row)
' Close the connection.
cn.Close( )
-
Jan 8th, 2003, 06:58 PM
#2
You have to use the Update method in the DataAdapter.
-
Jan 9th, 2003, 02:27 AM
#3
Registered User
And as you are not using a typed dataset you have to use a CommandBuilder object to build the update command before the Update method Edneeis mentioned.
-
Jan 9th, 2003, 06:06 AM
#4
Fanatic Member
do you get a typed dataset from using the fillschema command thing before filling the dataset?
-
Jan 9th, 2003, 06:47 AM
#5
Registered User
Nope, you get a typed dataset by using the server explorer to drag database items to your form and then use the automaticly created DataAdapters to creat a Typed dataset. A schema file is then created for the dataset and a Dataset is created based on that schema file. There is other ways to do it for what I've read but that is the easiest way for sure, else you have to do alot of that schema coding yourself.
The building of the Command that I mentioned for a non type dataset is not that hard though.... If you have a DataAdapter calle OledbDataAdapter1 you can do the following....
Code:
Dim cmdb As New OleDb.OleDbCommandBuilder(OleDbDataAdapter1)
OleDbDataAdapter1.UpdateCommand = cmdb.GetUpdateCommand
Similar goes with the InsertCommand and DeleteCommand of course.
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
|