Ciao a tutti, vorrei chiederVi aiuto in merito all'aggiornamento di un database via form che NON avviene.
Premessa: Uso textbox bindati; Il primo campo del form è associato a una chiave primaria autoincrement , seed 1, step 1, cosi' dichiarata sia in sql che nel dataset. Il dataset è impostato su non copiare.
Vorrei usare il TableAdapter.Update che però genera una exception per chiave null. Il textbox è correttamente associato alla chiave. Il TableAdapter.Insert non lo posso usare perchè non accetta il campo chave come argomento(pare sia corretto) e usandolo come lo accetta genera cmq errore.
Ho risolto usando sintassi command ma è possibile che non sia possibile usare i metodi di aggiornamento database generati dalla configurazione del dataset?????
Di seguito posto i 2 casi:
NON FUNZIONA
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Validate()
TABLEBindingSource.EndEdit()
TABLETableAdapter.Update(MYDATASET.TABLEDataTable)
End Sub
FUNZIONA
Dim cn As New SqlClient.SqlConnection
cn.ConnectionString = (My.Settings.MyConnectionString.ToString)
Dim cmd As New System.Data.SqlClient.SqlCommand
cmd.CommandType = System.Data.CommandType.Text
cmd.CommandText = "INSERT INTO TABLE (tb1 , tb2, tb3, tb4, cb1, cb2) VALUES (" _
& CType(TextBox1.Text, Decimal) & _
" , '" & TextBox2.Text & _
"' , " & TextBox3.Text & _
" , " & TextBox4.Text & _
" , '" & CheckBox1.Checked & _
"' , '" & CheckBox2.Checked & "')"
cmd.Connection = cn
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
Grazie per la vostra pazienza e gentile aiuto. Ciao.