Windows Develop Bookmark and Share   
 index > Windows Forms General > ADO.net and MS Access Errors
 

ADO.net and MS Access Errors

I am trying to update/insert/delete data using ADO.net connection to MS Access tables.  I have successfully created a connection to a table and can successfully insert data into the table using the update command.  But when i try to amend data i use the oledbcommandbuilder and i get the following error.

Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.

So to test this using visualbasic.net example i tried the following using a sqldataadapter which worked fine!

  Dim strconnection As String = "data source =stalis-2k2;initial catalog = Northwind;" _
        & "Integrated security=true"
        Dim cn As SqlClient.SqlConnection = New SqlClient.SqlConnection(strconnection)

        Dim strselect As String = "SELECT Categories.* FROM Categories "
        Dim da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(strselect, cn)

        Dim autogen As New SqlClient.SqlCommandBuilder(da)

        Dim ds As DataSet = New DataSet
        da.Fill(ds, "Categories")

        Dim dt As DataTable = ds.Tables("Categories")

        Dim row As DataRow = dt.Select("categoryName = 'Dairy Products'")(0)
        row("Description") = "Milk"
        

        da.Update(ds, "Categories")

        cn.Close()

Then i created a table the same as Categories from SQL Server in MS Access and changed all the commands in the above example to oledb and got the above error message again!  All of the examples i look up relate to SQL Server not Access any ideas on what i'm doing wrong??????????????
MigrationUser 1  Monday, October 06, 2003 8:37 AM
Ok, i've managed to figure this bit out, by adding key on the table i have now got futher.  My next problem is that i am populating a dataset from an access table, then binding the dataset to a datagrid.  I am then editing data in the front end and when i do the update i get Query to Complex!  My table has about 150 columns and 37 rows, i am assuming there is a limit to the amount.

Does anyone know any other ways of doing this, it has to be from Access tables and linked to a datagrid?

Thanks
MigrationUser 1  Monday, October 06, 2003 9:52 AM
The only thing I can guess is that you have created the Categories table without a primary key? I don't know, but I just tried this block of code using the sample Northwind database that comes with Microsoft Access, and it worked perfectly fine:

Private Const DataPath As String = _
 "D:\Program Files\Microsoft Office\" & _
 "Office11\Samples\Northwind.mdb"

Public Shared ReadOnly _
 OleDbConnectionString As String = _
 "Provider=Microsoft.Jet.OLEDB.4.0;" & _
 "Data Source=" & DataPath

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles Button1.Click
  Dim cn As New OleDbConnection(OleDbConnectionString)

  Dim strselect As String = "SELECT Categories.* FROM Categories "
  Dim da As New OleDbDataAdapter(strselect, cn)

  Dim autogen As New OleDbCommandBuilder(da)

  Dim ds As DataSet = New DataSet
  da.Fill(ds, "Categories")

  Dim dt As DataTable = ds.Tables("Categories")

  Dim row As DataRow = _
   dt.Select("categoryName = 'Dairy Products'")(0)
  row("Description") = "Milk"

  da.Update(ds, "Categories")
  cn.Close()
End Sub

Can you try it with the sample that comes with Access? Otherwise, I can't see why it wouldn't work... 
MigrationUser 1  Monday, October 06, 2003 10:31 AM
Thanks, just worked that one out.  Now having problems with Query to Complex error messages.  I've now got a dataset containing the data from the access table which is bound to a datagrid, i am changing the data and then updating and getting the above error.

I have about 150 columns in the table and 37 rows, is access limited to the amount of data i can amend in this way?  Is there any other way of using a datagrid from Access tables?  Or shall i just start using SQL Server tables?
MigrationUser 1  Monday, October 06, 2003 10:44 AM
It's not the number of rows that matters, it's going to be the number of columns (if you're getting a "Query too complex" error. To verify this, limit the number of columns (say to 10) and see if you get the same error. If you do, it's something else. 
MigrationUser 1  Monday, October 06, 2003 12:16 PM

You can use google to search for other answers

Custom Search

More Threads

• KeyButton ENTER as navigation
• Multiple non-modal windows
• Converting VB.Net with Access to VB.Net with SQL Server
• Combo Boxes
• Unable to get the window handle for the 'WebBrowser' control. Windowless ActiveX controls are not supported
• How to get a pathname to a file in my project
• CheckedListBox in the Property window
• TabControl: Custom TabPageCollection?
• HelpProvider - Line break & Min/Max
• How to code it in VC#? (interactive between two listbox)