By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,057 Members | 1,407 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,057 IT Pros & Developers. It's quick & easy.

database saving

P: 37
I'm using VB 2005 to create a simple application where authorised users can edit the database. Firstly, the database will be imported into a datatable and into a datagrid.

Expand|Select|Wrap|Line Numbers
  1. Public Class Databaseupdatting
  2.     Dim dt As New DataTable()
  3.  
  4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.         dt.Clear()
  6.         Dim SQLCon As New SqlClient.SqlConnection("Data Source=TP-TM3282WXMI\SQLEXPRESS;Initial Catalog=ProteinDatabase;Integrated Security=True;Pooling=False")
  7.         SQLCon.Open()
  8.         Dim SQLCom As New SqlClient.SqlCommand("SELECT * FROM Table_1", SQLCon)
  9.         Dim DataAdapter As New SqlClient.SqlDataAdapter(SQLCom)
  10.         DataAdapter.Fill(dt)
  11.         DataAdapter.Dispose()
  12.         dvgDisplay.DataSource = dt
The above code has been successfully executed but when user clicks the save button, the program is supposed to return the number of rows saved after the update command is executed. The error message is Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information and it points to the line "changes=DataAdapter.Update(dt)"

Expand|Select|Wrap|Line Numbers
  1. Dim changes As Integer
  2.             Dim SQLCon As New SqlClient.SqlConnection("Data Source=TP-TM3282WXMI\SQLEXPRESS;Initial Catalog=ProteinDatabase;Integrated Security=True;Pooling=False")
  3.             Dim changes As Integer
  4.             SQLCon.Open()
  5.             Dim SQLCom As New SqlClient.SqlCommand("SELECT * FROM Table_1", SQLCon)
  6.             Dim DataAdapter As New SqlClient.SqlDataAdapter(SQLCom)
  7.             Dim CommandBuilder As New SqlClient.SqlCommandBuilder(DataAdapter)
  8.             changes = DataAdapter.Update(dt)
  9.             DataAdapter.Dispose()
  10.             If changes > 0 Then
  11.                 MsgBox(changes & " changed rows were made.")
  12.             Else
  13.                 MsgBox("No changes made")
Can someone help me debug? I am near my dateline of my project and I will appreciate if someone can help. Thanks.
Nov 24 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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