Problema Grilla VB.net
Publicado por pamela (2 intervenciones) el 10/06/2010 14:11:30
BUenas, tengo una grilla q la relleno cargando un exel, lo q necesito ahora es hacer un UPdate en una tabla de sqlserver, el codigo es el siguiente:
Dim modificar As New SqlCommand
modificar.CommandText = "update servicio1 set nombre=@nombre where id_servicio=" & Me.DataGridView1.CurrentRow.Cells("id_servicio").Value
modificar.Connection = conexion
Me.da.UpdateCommand = modificar
Dim f As Integer
For f = 0 To Me.DataGridView1.RowCount - 1 Step 1
Me.da.UpdateCommand.Parameters.Add(New SqlParameter("@nombre", SqlDbType.VarChar))
Me.da.UpdateCommand.Parameters("@nombre").Value = Me.DataGridView1.Rows(f).Cells("nombre").Value.ToString()
Me.da.UpdateCommand.Connection = conexion
Me.da.UpdateCommand.ExecuteNonQuery()
Next
cuando lo ejecuto me dice:
The Variable "nombre" has alredy been declared.
si le saco el for, me hace el update, pero solo del primer registro. Cual podra ser el error.?? Muchas GRacias...
Dim modificar As New SqlCommand
modificar.CommandText = "update servicio1 set nombre=@nombre where id_servicio=" & Me.DataGridView1.CurrentRow.Cells("id_servicio").Value
modificar.Connection = conexion
Me.da.UpdateCommand = modificar
Dim f As Integer
For f = 0 To Me.DataGridView1.RowCount - 1 Step 1
Me.da.UpdateCommand.Parameters.Add(New SqlParameter("@nombre", SqlDbType.VarChar))
Me.da.UpdateCommand.Parameters("@nombre").Value = Me.DataGridView1.Rows(f).Cells("nombre").Value.ToString()
Me.da.UpdateCommand.Connection = conexion
Me.da.UpdateCommand.ExecuteNonQuery()
Next
cuando lo ejecuto me dice:
The Variable "nombre" has alredy been declared.
si le saco el for, me hace el update, pero solo del primer registro. Cual podra ser el error.?? Muchas GRacias...
Valora esta pregunta


0