473,395 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dynamic SQL generation for the UpdateCommand is not supported

1
Getting the following error when running my application.

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

On form load it reads the database to the textboxes for the user, they can then change their details.

On clicking the save button I am attempting to update the database with the information from a textbox but the above error is thrown and I'm not a bit lost.

Here is my code

Expand|Select|Wrap|Line Numbers
  1.     Private Sub WriteRecords()
  2.         'Database Connection for save
  3.         Dim Con As New OleDb.OleDbConnection
  4.         Dim ds As New DataSet
  5.         Dim da As OleDb.OleDbDataAdapter
  6.         Dim sqlcode As String
  7.  
  8.  
  9.         Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\test.mdb; User ID=Admin; Password= ;"
  10.         Con.Open()
  11.         sqlcode = "SELECT * FROM [User]"
  12.         da = New OleDb.OleDbDataAdapter(sqlcode, Con)
  13.         da.Fill(ds, "RefUser")
  14.         Con.Close()
  15.  
  16.         'Update dataset with user info
  17.  
  18.         ds.Tables("RefUser").Rows(0).Item(1) = tb_fname.Text
  19.  
  20.         'Update data
  21.         Dim cb As New OleDb.OleDbCommandBuilder(da)
  22.         da.Update(ds, "RefUser")
  23.  
  24.         'Close the form
  25.         Closeform()
  26.     End Sub
Any help would be great Thanks
Mar 19 '10 #1
3 3868
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Mar 19 '10 #2
tlhintoq
3,525 Expert 2GB
Until another expert with more experience in this can offer more targeted help, I can at least point you at these:

Database How-to parts 1 and 2
Database tutorial Part 1
Database tutorial Part 2
Mar 19 '10 #3
CroCrew
564 Expert 512MB
Hello spv4u,

The example below is just that an example. I would put all the database activity in a class and call functions from the class. But, for this example I put it all in the code behind of the form to keep it simple.

Elements on the form:
BookDropDownList – is a Drop Down List that get populated on the load of the page. Every time a book is selected from the drop down the page gets reloaded and the text boxes get populated with the selected books data.

UpdateBook – is a button on the form that when pressed the data from the text boxes then are used to update the corresponding data for the selected book.

xKeyID – an editable textbox populated with the selected book from the BookDropDownList.

xTitle – an editable textbox populated with the selected book from the BookDropDownList.

xAuthor – an editable textbox populated with the selected book from the BookDropDownList.

xPublisher – an editable textbox populated with the selected book from the BookDropDownList.


Anyways, I hope this helps you out,
CroCrew~


Expand|Select|Wrap|Line Numbers
  1. Imports System.Data
  2. Imports System.Data.OleDb
  3. Imports ADODB
  4.  
  5. Public Class Form1
  6.     Private Function ConnectionString() As String
  7.         Private ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.IO.Path.GetFullPath("Database\TheLibrary.mdb")
  8.     End Function
  9.  
  10.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  11.         BookDropDownList.DataSource = GetBooks()
  12.         BookDropDownList.DataValueField = "KeyID"
  13.         BookDropDownList.DataTextField = "Title"
  14.         BookDropDownList.DataBind()
  15.     End Sub    
  16.  
  17.     Protected Sub BookDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BookDropDownList.SelectedIndexChanged
  18.         Dim OpenBook As DataSet = GetBooks(BookDropDownList.SelectedValue)
  19.         xKeyID.Text = OpenBook.Tables("mydata").Rows(0).Item("KeyID").ToString
  20.         xTitle.Text = OpenBook.Tables("mydata").Rows(0).Item("Title").ToString
  21.         xAuthor.Text = OpenBook.Tables("mydata").Rows(0).Item("Author").ToString
  22.         xPublisher.Text = OpenBook.Tables("mydata").Rows(0).Item("Publisher").ToString
  23.     End Sub    
  24.  
  25.     Protected Sub UpdateBook_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateBook.Click
  26.         If (UpdateBook()) Then
  27.             ErrorAndInformationDiv.InnerHtml = "Update completed.<br / >&nbsp;"
  28.         Else
  29.             ErrorAndInformationDiv.InnerHtml = "Error: 134.649.093<br / >&nbsp;"
  30.         End If
  31.     End Sub    
  32.  
  33.     Function GetBooks(Optional ByVal KeyID As Integer = 0) As DataSet
  34.         Dim SQL As String = "SELECT * FROM Books"
  35.  
  36.         If (KeyID > 0) Then
  37.             SQL &= " WHERE KeyID = " & KeyID
  38.         End If
  39.  
  40.         Dim dbConnection As MySqlConnection = New MySqlConnection()
  41.         dbConnection.ConnectionString = ConnectionString()
  42.  
  43.         Dim mylocalDataSet As DataSet = New DataSet
  44.         Dim myDataAdapter As New MySqlDataAdapter(SQL, dbConnection)
  45.         myDataAdapter.Fill(mylocalDataSet, "myData")
  46.  
  47.         If dbConnection.State = Data.ConnectionState.Closed Then
  48.             dbConnection.Open()
  49.         End If
  50.  
  51.         GetBooks = mylocalDataSet
  52.  
  53.         If dbConnection.State = Data.ConnectionState.Open Then
  54.             dbConnection.Close()
  55.             dbConnection.Dispose()
  56.         End If
  57.     End Function
  58.  
  59.     Function UpdateBook() As Boolean
  60.        Try
  61.             Using connection As New SqlConnection(ConnectionString())
  62.                 connection.Open()
  63.  
  64.                 Dim commandText As String = "UPDATE Books SET Title=@Title, Author=@Author , Publisher=@Publisher WHERE KeyID = @KeyID"
  65.  
  66.                 Using command As New SqlCommand(commandText, connection)
  67.                     command.Parameters.AddWithValue("@KeyID", xKeyID.Text)
  68.                     command.Parameters.AddWithValue("@Title", xTitle.Text)
  69.                     command.Parameters.AddWithValue("@Author", xAuthor.Text)
  70.                     command.Parameters.AddWithValue("@Publisher", xPublisher.Text)
  71.                     command.CommandTimeout = 300
  72.                     command.ExecuteNonQuery()
  73.                 End Using
  74.             End Using
  75.             Return True
  76.         Catch ex As Exception
  77.             Return False
  78.         End Try
  79.     End Function    
  80.  
  81.  
Mar 19 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Patrick | last post by:
Hello I have a Datalist, that I fill with the PopulateList() method. This method selects all Items from Database and binds the Dataset to the DataLilst. Now, when clicking Edit, in the...
4
by: DraguVaso | last post by:
Hi, For my VB.NET application I have the following situation: 2 tables on my SQL Server: tblAccounts and tblRules. For each Account there are many Rules (so tblRules is linked to my tblAccounts...
2
by: Irfan | last post by:
hi, I am getting the following error. Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information when i try to use da.update I squeezed...
0
by: Gancy | last post by:
Hi, I have data access tier designed in such a way, just by changnging application settings, same lines of code is made to work with both MS SQL Server or MS Access. Code works fine with MS SQL...
2
by: Ghada Al-Mashaqbeh via DotNetMonster.com | last post by:
Hi all, I am facing a problem in dynamic code generation at run time, the problem occurs when the dynmaic code use global data exist within the original application. Lets say that my...
5
by: pittendrigh | last post by:
There must be millions of dynamically generated html pages out there now, built by on-the-fly php code (and jsp, perl cgi, asp, etc). Programatic page generation is transparently useful. But...
5
by: =?Utf-8?B?QUEyZTcyRQ==?= | last post by:
The full error message is "Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information." I am getting this error when...
0
by: pieandpeas | last post by:
Hi, I'm having a problem with my code, I am doing the following - retrieving a field from a table, which is linked to another table, i'm only updating one of the fields in one of the two tables......
16
OuTCasT
by: OuTCasT | last post by:
Anyone know how to get passed this prblem Dynamic SQL generation is not supported against multiple base tables
0
by: Giovanni | last post by:
Hi, I'm new in vs2k8 and I'm trying to build up an ASP application that uses a DB. Situation: 2 tables related by a key (pk->fk). A Gridview on a web page that show me the 2 tables join query's...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.