只保存数据网格的第一行。我想保存所有记录: 这是我的保存按钮的代码
MysqlConn.Open()
Try
Dim Query as String
For each row As DataGridViewRow In dgv1.Rows
If row.Cells(0).FormattedValue <> "" And row.Cells(1).FormattedValue <> "" Then
Query = "insert into items(name,other) values ('"& Cstr(row.Cells(0).FormattedValue) &"' , '"& Cstr(row.Cells(1).FormattedValue) &"')"
COMMAND = New MySqlCommand(Query, MysqlConn)
READER = COMMAND.ExecuteReader
dgv1.Rows.Clear()
End If
Next
If result = 0 Then
Msgbox("Error")
Else
Msgbox("Saved")
End If
Catch ex As Exception
MessageBox.show(ex.Message)
End Try
MysqlConn.Dispose()
答案 0 :(得分:0)
dgv1.Rows.Clear()可能是麻烦