Error to edit and Update Record in Sql Database

jeva39

Well-known member
Joined
Jan 28, 2005
Messages
135
Location
Panama
Programming Experience
1-3
The problem: When I add a new record, all work fine but if I try to edit and update any record, I receive this error:

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

The Code for New Record is:

Private Sub btnGrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGrabar.Click
Dim dtr As DataRow
If txtTema.Text = "" Or txtTopico.Text = "" Or txtClase.Text = "" Then
MessageBox.Show("Tema, Topico o Clase no pueden estar en blanco", vbExclamation)
txtTema.Focus()
Exit Sub
End If
dtr = Me.dst.Tables("Ayuda").NewRow
dtr("Clase") = Me.txtClase.Text
dtr("Tema") = Me.txtTema.Text
dtr("Topico") = Me.txtTopico.Text
dtr("Libro") = Me.txtLibro.Text
dtr("Capitulo") = Me.txtCapitulo.Text
dtr("Cuaderno") = Me.txtCuaderno.Text
dtr("Pagina") = Me.txtPagina.Text
dtr("Info") = Me.txtInfo.Text
dtr("Programa") = Me.txtPrograma.Text
Me.dst.Tables("Ayuda").Rows.Add(dtr)
Try
Me.dta.Update(Me.dst, "Ayuda")
Catch eUpdate As System.Exception
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
End Try
Me.myGrid.Refresh()
posChange()
Me.CargaDatos()
Botones("BASE")
End Sub

The code for edit is:

Private Sub btnActualizar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnActualizar.Click
Dim dtr As DataRow
If txtTema.Text = "" Or txtTopico.Text = "" Or txtClase.Text = "" Then
MessageBox.Show("Tema, Topico o Clase no pueden estar en blanco", vbExclamation)
txtTema.Focus()
Exit Sub
End If
dtr = Me.dst.Tables("Ayuda").Rows(Me.IposAct)
dtr("Clase") = Me.txtClase.Text
dtr("Tema") = Me.txtTema.Text
dtr("Topico") = Me.txtTopico.Text
dtr("Libro") = Me.txtLibro.Text
dtr("Capitulo") = Me.txtCapitulo.Text
dtr("Cuaderno") = Me.txtCuaderno.Text
dtr("Pagina") = Me.txtPagina.Text
dtr("Info") = Me.txtInfo.Text
dtr("Programa") = Me.txtPrograma.Text
dtr("ID") = Me.txtID.Text
Try
Me.dta.Update(Me.dst, "Ayuda")
Catch eUpdate As System.Exception
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
End Try
posChange()
Me.CargaDatos()
Botones("BASE")
End Sub

Both event handlers are similar but this sub causes the error. Please: what is wrong? (When create the connection I use CommandBuilder)

Thanks in advanced for your help!!!

Jorge Villamizar
 
Back
Top