Hi ,
Could anyone show me how to do simple operations (inserts , delete , update) against access db in disconnected mode .
there are lots of confusing methods (datatable , datarow , dataset , dataadpter,datareader etc).I don't know from where to start .
anyone would be of assistance guys!thanx
not really what I'm looking for though.Unfortunatly I've read that before. Well , basically how can I add some text to databse in disconnected mode ? that's all the story .
and of course thanx for the help.
A lot of it is a matter of preference or how you are displaying the data. If you are using datarows and a dataset then you can use something like this:
VB Code:
'get a blank new row from the table so it has all the structure
Dim newRow as datarow=ds.Tables(0).NewRow
'fill the row with data
newRow("Field")="Some data goes here"
'now the dataset has the new data but it is disconnected
'so the database itself doesn't so we use a dataadapter to
'update the actual database
'connect to the database
cnn.Open()
da.Update(ds.Tables(0))
cnn.Close()
Of course this assumes you have already setup the dataset and dataadapter. Setting up the dataadapter is just a matter of providing the SQL statements or Commands it will use to perform the various functions. So if you want it to Insert new rows make sure it has an InsertCommand, likewise for Updates, the UpdateCommand....
You can also just add data directly to the database using Command objects (either SQL or OLEDB). This is a lot like the old vb6 way and doesn't require a dataset or datarows.
VB Code:
'build sql statement
Dim sb As New System.Text.StringBuilder()
sb.Append("INSERT INTO MyTable (MyField1,MyField2) VALUES (")
'fill in values
sb.Append(value1 & ",")
sb.Append(value2 & ")")
'make command
Dim cmd As New OleDb.OleDbCommand(sb.ToString, cnn)
'open connection
cnn.Open()
'execute
cmd.ExecuteNonQuery()
cnn.Close()
That should give you a push in the right direction. I didn't test it so I hope I didn't forget something.
Please post your database you are using with the project. I have Office XP and cannot edit the Access 97 database you sent (which only has the 'URL' field in 'Table1'). Otherwise I will make an Access 2000 DB with the fields you have in your code (but then you won't be able to edit the table unless you have Access 2000 or greater).