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