我需要更新存储过程,就像消息框读取datagridview的每个项目一样。它只保存消息框读取的最后一条记录。需要帮助:(
For Each row As DataGridViewRow In DataGridView1.Rows
Dim strunitprice As String = CDbl(row.Cells(7).FormattedValue) + Val(CDbl(TXTNET.Text))
'opening the connection
x = MessageBox.Show(CDbl(row.Cells(7).FormattedValue) + Val(CDbl(TXTNET.Text)))
If x = DialogResult.OK Then
Label27.Text = CDbl(row.Cells(7).FormattedValue) + Val(CDbl(TXTNET.Text))
End If
Dim dr5 As SqlDataReader
Dim myCommand As SqlCommand
connectme.Open()
myCommand = New SqlCommand("Select * from quotation", connectme)
dr5 = myCommand.ExecuteReader()
While dr5.Read()
connectme1.Close()
Dim c As New SqlCommand("updatequotation", connectme1)
Dim Adapter As SqlDataAdapter = New SqlDataAdapter(c)
c.CommandType = CommandType.StoredProcedure
c.Parameters.Add("@Customer_Name", SqlDbType.NVarChar).Value = txtclientname.Text
c.Parameters.Add("@Date_Today", SqlDbType.VarChar).Value = Label7.Text
c.Parameters.Add("@Net_Income", SqlDbType.VarChar).Value = TXTNET.Text
c.Parameters.Add("@Unit_Price", SqlDbType.VarChar).Value = Label27.Text
connectme1.Open()
c.ExecuteNonQuery()
connectme1.Close()
End While
dr5.Close()
connectme.Close()
Next row
End If
答案 0 :(得分:0)
为什么要关闭连接然后从中创建命令。从while循环中删除connection.close()并再次运行代码。它应该工作。