Hi, i want to save into my sql server 2000 database multiples rows of a datagridview. i tryed something that first was working good, but i did a code change removing a column so now i'm trying to save again but i can't do it. It's shows me a message error like this: THERE ARE FEWER COLUMNS IN THE INSERT STATEMENT THAN VALUES ESPECIFIED IN THE VALUES CLAUSE. I rewrite the code, delete and add a new table and my code has the same values in the insert than my values clause. I don't know what else i have to do.
Here is my code, thanks for your answers.
Code:Private Sub cmdAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAceptar.Click Try Const CCon As String = "data source = DATASERVER;Initial Catalog= CATV;user id = sa;password=sa" Dim sqlCon As New Data.SqlClient.SqlConnection(CCon) Dim sqlQry As New SqlClient.SqlCommand("Insert into COMPRAS_ENC(PED_NRO, PED_FCH, PROV_ID, TIP_COMPRA) values ('" & _ txtNumShop.Text & "', '" & dtpFecha.Text & "', '" & cboCodProv.Text & "', '" & cboCompra.Text & "' )", sqlCon) sqlCon.Open() If grid1.Rows.Count > 0 Then For i As Integer = 0 To grid1.Rows.Count - 1 Dim sqlQry2 As New SqlClient.SqlCommand("Insert into DETALLE_COMPRA(PED_NRO, PED_LIN, MED_ID, CANT_COM, PRE_UNI) values ('" & _ txtNumShop.Text & "', " & Me.grid1.Rows(i).Cells(0).Value.ToString & ", '" & _ Me.grid1.Rows(i).Cells(1).Value.ToString & "', " & _ Me.grid1.Rows(i).Cells(2).Value.ToString & ", " & _ Me.grid1.Rows(i).Cells(3).Value.ToString & ")", sqlCon) sqlQry2.ExecuteNonQuery() Next End If sqlQry.ExecuteNonQuery() sqlCon.Close() Catch ex As Exception MessageBox.Show(ex.Message) End Try 'Me.Close() End Sub




Reply With Quote