我将数据添加到 datagridview,检查 datagridview 中的重复值并插入数据库。
前任。
Datagridview
Code:
130027646001
130027646002
130027646003
After add data to datagridview
Code:
130027646001
130027646002
130027646003
130027646004
130027646005
After to insert to database Result
130027646001
130027646002
130027646003
130027646001
130027646002
130027646003
130027646004
130027646005
But I want Result
130027646001
130027646002
130027646003
130027646004
130027646005
我想插入数据库不要将值仅 130027646004,130027646005 复制到数据库。我尝试编写代码 2 类型但并非全部工作。
此代码(类型一):
Dim sqlC As String = ""
Dim DT As New DataTable
Dim sendStatus As Integer
sqlC = "Select c.* "
sqlC &= "FROM Clother c
sqlC &= "WHERE c.No=" & tClother
DT = FShowData(sqlItem)
If DT.Rows.Count > 0 Then
For i As Integer = 0 To DgvItem.Rows.Count - 1
If DgvItem.Rows(i).Cells(0).Value <> DT.Rows(i).Item("Code") Then
sendStatus = FuncInsert(CStr(DgvItem.Rows(i).Cells(0).Value))
End If
Next
End If
此代码(类型二): 我编写代码但错误“对于 Int32,值太大或太小。无法在无列中存储 <130027646001>。预期类型是 Int32。”
Dim sqlC As String = ""
Dim DT As New DataTable
Dim sendStatus As Integer
sqlC = "Select c.* "
sqlC &= "FROM Clother c
sqlC &= "WHERE c.No=" & tClother
DT = FShowData(sqlItem)
If DgvItem.Rows.Count > 0 Then
For i As Integer = 0 To DgvItem.Rows.Count - 1
If (CStr(DgvItem.Rows(i).Cells("Code").Value) <> "") Then
Dim dr As DataGridViewRow
dr = DgvItem.Rows(i)
DT.TableName = "Code"
If DT.Rows.Count > 0 Then
For j As Integer = 0 To DT.Rows.Count - 1
If CStr(DgvItem.Rows(i).Cells("Code").Value) <> CStr(DT.Rows(j).Item("Code")) Then
sendStatus = FuncInsert(CStr(DgvItem.Rows(i).Cells(0).Value))
End If
Next
End If
DT.Rows.Add(dr.Cells("Code").Value).ToString() >> Error Line: Value was either too large or too small for an Int32.Couldn't store <130027646001> in No Column. Expected type is Int32.
End If
Next
End If
DT.Dispose()
DT = Nothing
桌布
Field Type
Code nvarchar