16,555
社区成员
发帖
与我相关
我的任务
分享
Dim strSql As String
For i As Integer = 0 To DataGridView1.Rows.Count - 1
strSql = "INSERT TableName( " & vbCrLf
strSql += " id" & vbCrLf 'id,cpb,hth,ddlb,fx,gj
strSql += " ,cpb" & vbCrLf
strSql += " ,hth" & vbCrLf
strSql += " ,ddlb" & vbCrLf
strSql += " ,fx" & vbCrLf
strSql += " ,gj" & vbCrLf
strSql += " )" & vbCrLf
strSql += " VALUES (" & vbCrLf
strSql += " ,'" & DataGridView1.Rows(i).Cells(0).Value & "'" & vbCrLf
strSql += " ,'" & DataGridView1.Rows(i).Cells(1).Value & "'" & vbCrLf
strSql += " ,'" & DataGridView1.Rows(i).Cells(2).Value & "'" & vbCrLf
strSql += " ,'" & DataGridView1.Rows(i).Cells(3).Value & "'" & vbCrLf
strSql += " ,'" & DataGridView1.Rows(i).Cells(4).Value & "'" & vbCrLf
strSql += " ,'" & DataGridView1.Rows(i).Cells(5).Value & "'" & vbCrLf
strSql += " )"
Next
'看你的datagridview情况定 如果不允许用户自增行的话就这么写,允许的话就dgrdName.rows.count -2
for i as Integer = 0 to dgrdName.rows.count -1
strSql = "INSERT TableName( " & vbCrLf
strSql += " nameID" & vbCrLf
strSql += " )" & vbCrLf
strSql += " VALUES (" & vbCrLf
strSql += " ,'" & dgrdName.Rows(i).Cells(1).Value & "'" & vbCrLf
strSql += " )"
Next