Acces Database  
Author Message
Harkernator





PostPosted: .NET Framework Data Access and Storage, Acces Database Top

Hi,

 

I'm trying to add some variables to an access database that has one table with three columns.

The code doesn't produce any errors but when I open the database file there is no data.

Here's my code

"data" as an instance of a dataset called RDXInfoDataSet

 

data.Table1.AddTable1Row(type, extn, linetype)

data.Table1.AcceptChanges()

data.AcceptChanges()

 

Any ideas why it's not working



.NET Development20  
 
 
ahmedilyas





PostPosted: .NET Framework Data Access and Storage, Acces Database Top

well firstly, you shouldnt use AcceptChanges() in this case as it will tell the DataAdapter (which fills the records to the dataset from the database and updates the database from the new values in the dataset) that there are no updates to be made but infact there is. So comment that out.

Secondly, to finally update the database, you need to use the DataAdapter and use its Update() method, giving it the dataset or datatable to update with. However you need to have the correct Commands in place in order to successfully update the database, commands like InsertCommand, DeleteCommand, UpdateCommand. There are many examples on these forums, so take a look and see which one can help you.

You may also be interested in this:

http://msdn2.microsoft.com/en-us/library/system.data.oledb.oledbdataadapter.aspx

http://msdn2.microsoft.com/en-us/library/at8a576f.aspx

Does this give you some guidence



 
 
Paul P Clement IV





PostPosted: .NET Framework Data Access and Storage, Acces Database Top


There is an FAQ on this:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=427451&SiteID=1



 
 
Harkernator





PostPosted: .NET Framework Data Access and Storage, Acces Database Top

It's ok, I've worked it out already.

Here's the final code:

Dim datata As New RDXInfoDataSetTableAdapters.Table1TableAdapter

Dim datatable As New RDXInfoDataSet.Table1DataTable

datata.Insert(type, extn, linetype)

datata.Update(datatable)

Thanks anyway!


 
 
Harkernator





PostPosted: .NET Framework Data Access and Storage, Acces Database Top

Okay, this is annoying.

 

I've only just managed to put the full code in to my app (been a bit busy).

The above lines of code worked absolutely fine for my test file.

I've now put it into a For loop which adds about 550 rows - and it's not working.

Even more agetatingly, if I remove my for loop, and just pass it some raw data, it doesn't work still!

 

Theres actually a large group of Ifs together which are turning one phrase in to a collection of values.

The code doesn't produce any errors, but the database is empty.

 

Dim datata As New RDXInfoDataSetTableAdapters.ExtensionsTableAdapter

Dim datatable As New RDXInfoDataSet.ExtensionsDataTable

 

datata.Insert(type, extn, linetype, interfacecard, access, usage)

datata.Update(datatable)

 

if I put a breakpoint at the "datata.Insert" line, and check the values of the variables, they contain what I expect them to.

 I've used this code to test the actual database routine - I've just put this on the event handler for a button:

Dim type = "type"

Dim extn = "type1"

Dim linetype = "type2"

Dim interfacecard = "type3"

Dim access = "type4"

Dim usage = "type5"

datata.Insert(type, extn, linetype, interfacecard, access, usage)

datata.Update(datatable)

Still, the database is empty!

Regards


 
 
Paul P Clement IV





PostPosted: .NET Framework Data Access and Storage, Acces Database Top


Did you check if solution #2 in the link I posted applies to you

 
 
Harkernator





PostPosted: .NET Framework Data Access and Storage, Acces Database Top

I had - but I didn't read it properly...

I only read the part about AcceptChanges, which didn't apply to me as I wasn't using it.

I missed the part about copying the MDB file...

That was it!