0
我只是想增加ID与限制等同于其他表插入vb.net如何递增的ID,如果我按一下按钮
我对此
没有问题,唯一的问题是,我上倾斜的id码递增直到限位
id列2
1 ----------- 0
2 ----------- 5
3 ----------- 0
等等,像这样,通过cliking插入按钮,ID应该由一个直到极限增加一个
任何人都可以请帮助我
RecordDate.Text = MyFormat
Dim antinull As Integer = Format(0)
BadBeg.Text = antinull
WarePcs.Text = antinull
CustPcs.Text = antinull
Returned.Text = antinull
BadEnd.Text = antinull
Try
Str = "insert into BadWarehouseInv values("
Str += Id.Text.Trim()
Str += ","
Str += """" & RecordDate.Text.Trim() & """"
Str += ","
Str += """" & BadBeg.Text.Trim() & """"
Str += ","
Str += WarePcs.Text.Trim()
Str += ","
Str += CustPcs.Text.Trim()
Str += ","
Str += Returned.Text.Trim()
Str += ","
Str += """" & BadEnd.Text.Trim() & """"
Str += ")"
Con.Open()
Cmd = New OleDbCommand(Str, Con)
Cmd.ExecuteNonQuery()
Dst.Clear()
Dad = New OleDbDataAdapter("SELECT * FROM BadWarehouseInv ORDER BY Id", Con)
Dad.Fill(Dst, "stock")
Con.Close()
Catch ex As Exception
MessageBox.Show("Could Not Insert Record!!!")
MsgBox(ex.Message & " - " & ex.Source)
Con.Close()
请考虑[String.Format()](http://msdn.microsoft.com/en-us/library/fht0f5be%28v=vs.80%29.aspx):http://stackoverflow.com/问题/ 7054069 /插入 - 形成 - 字符在字符串格式 – tjameson 2013-03-22 10:15:36
比这更好,请考虑参数化查询! http://stackoverflow.com/questions/542510/how-do-i-create-a-parameterized-sql-query-why-should-i – 2013-03-22 10:16:18
@tjameson'String.Format'可能更具可读性,但同样易受影响注射,你应该推荐使用'SqlParameter's来代替。 – 2013-03-22 10:17:19