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.
[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.