RE:Problema al grabar grilla
Damian este es el código que utilizo para llamar a la base de datos:
Sub llenar_grilla(Optional ByVal opcion As String = "")
Dim valor As String
If opcion = "" Then
If CMBPATENTE.Text = "---" Then
valor = CMBPATENTE1.Text
Else
If TXTITEM.Text <> "" Then
valor = TXTITEM.Text
Else
valor = CMBPATENTE.SelectedValue
End If
End If
Else
valor = opcion
End If
Try
da = New Data.SqlClient.SqlDataAdapter("Select * From Presupuesto2 where Patente_Vehiculo = '" + valor.ToString + "' ", conn)
da.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim builder As Data.SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder(da)
Dim ds As New DataSet
da.Fill(ds, "Grilla")
Dim vista As DataView = New DataView(ds.Tables("Grilla"), " ", "N_Filas asc", DataViewRowState.CurrentRows)
Grilla.DataSource = vista
Grilla.DataBind()
Session.Add("tabla", ds)
Session.Add("cmd", builder)
'contador_items.Text = ds.Tables("Grilla").Rows.Count
'TXTITEM.Text = contador_items.Text
Catch ex As Data.SqlClient.SqlException
MsgBox("Error:" & vbCrLf & ex.Message, MsgBoxStyle.Critical, "FVJ")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
y este es el código que utilizo para grabar:
Sub Graba()
Dim ds As DataSet
ds = Session("tabla")
Dim builder As SqlCommandBuilder
builder = Session("cmd")
Dim sqladd As New SqlCommand
sqladd = builder.GetInsertCommand()
sqladd.Connection = conn
Dim sqlmod As New SqlCommand
sqlmod.Connection = conn
Dim sqldel As New SqlCommand
sqldel.Connection = conn
Dim contador As Integer = 0
Try
sqldel.CommandText = "delete from Repuestos1 where (Patente_Vehiculo='" _
+ ds.Tables("Grilla").Rows(0).Item("Patente_Vehiculo").ToString.Trim + "')"
sqldel.ExecuteNonQuery()
Catch ex As Exception
MsgBox(sqldel.CommandText)
MsgBox("error en formatear los datos")
End Try
For Each fila As DataRow In ds.Tables("Grilla").Rows
If Not fila.RowState = DataRowState.Deleted Then
sqladd.Parameters(0).Value = fila("N_Filas")
sqladd.Parameters(1).Value = fila("Cant_Repuestos")
sqladd.Parameters(2).Value = fila("Repuestos")
sqladd.Parameters(3).Value = fila("Patente_Vehiculo")
sqladd.Parameters(4).Value = fila("Activo")
sqladd.ExecuteNonQuery()
End If
Next
End Sub
se supone que esta última tabla no posee datos, ojala que mem puedas ayudar.