database saving

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gyap88
    New Member
    • Jul 2007
    • 37

    database saving

    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.

    [CODE=vbnet]Public Class Databaseupdatti ng
    Dim dt As New DataTable()

    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
    dt.Clear()
    Dim SQLCon As New SqlClient.SqlCo nnection("Data Source=TP-TM3282WXMI\SQLE XPRESS;Initial Catalog=Protein Database;Integr ated Security=True;P ooling=False")
    SQLCon.Open()
    Dim SQLCom As New SqlClient.SqlCo mmand("SELECT * FROM Table_1", SQLCon)
    Dim DataAdapter As New SqlClient.SqlDa taAdapter(SQLCo m)
    DataAdapter.Fil l(dt)
    DataAdapter.Dis pose()
    dvgDisplay.Data Source = dt[/CODE]
    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=DataAd apter.Update(dt )"

    [CODE=vbnet]Dim changes As Integer
    Dim SQLCon As New SqlClient.SqlCo nnection("Data Source=TP-TM3282WXMI\SQLE XPRESS;Initial Catalog=Protein Database;Integr ated Security=True;P ooling=False")
    Dim changes As Integer
    SQLCon.Open()
    Dim SQLCom As New SqlClient.SqlCo mmand("SELECT * FROM Table_1", SQLCon)
    Dim DataAdapter As New SqlClient.SqlDa taAdapter(SQLCo m)
    Dim CommandBuilder As New SqlClient.SqlCo mmandBuilder(Da taAdapter)
    changes = DataAdapter.Upd ate(dt)
    DataAdapter.Dis pose()
    If changes > 0 Then
    MsgBox(changes & " changed rows were made.")
    Else
    MsgBox("No changes made")[/CODE]
    Can someone help me debug? I am near my dateline of my project and I will appreciate if someone can help. Thanks.
    Last edited by Killer42; Nov 30 '07, 01:14 AM. Reason: Added CODE=vbnet tags
Working...