【发布时间】:2013-03-12 03:43:00
【问题描述】:
我只想增加插入的id,限制等于其他表
我没意见
唯一的问题是,我不能在 id 上增加代码直到达到限制
id 列 2
1------------0
2------------5
3-----------0
以此类推,像这样,通过单击插入按钮,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()
【问题讨论】:
-
比这更好,请考虑参数化查询! stackoverflow.com/questions/542510/…
-
@tjameson
String.Format可能更具可读性,但同样容易被注入,您应该建议使用SqlParameters 代替。 -
@MattWilko - 是的!我花了一点时间才意识到这是一个 SQL 查询。我看到了一堵字符串连接的墙和jumped to conclusions。
-
那些论坛很复杂,我想要简单易懂的,它将用于我在系统分析和开发中的重新防御,我没有时间了,请:(
标签: vb.net ms-access auto-increment