|
数据库中有ID字段,INT,现在要每次添加新记录时候,ID自段自动+1,要怎么实现?下面是我代码:
Public Overrides Sub SaveForAdd2()
Dim drData As DataRow = DataSet11.Tables("申请表").NewRow()
Try
drData("id") = TextBox36.Text
drData("申请车间") = TextBox30.Text()
drData("申请班组") = TextBox31.Text()
drData("申请人") = TextBox33.Text()
drData("科目负责人") = TextBox34.Text()
drData("申请日期") = DateTimePicker1.Value.ToString("yyyy-MM-dd")
drData("名称") = TextBox35.Text()
drData("单价") = TextBox36.Text()
drData("数量") = TextBox37.Text()
drData("合计") = TextBox38.Text()
drData("备注") = TextBox39.Text()
drData("用途") = TextBox40.Text()
Catch ex As Exception
MessageBox.Show("数据格式不正确!")
Exit Sub
End Try
Try
DataSet11.Tables("申请表").Rows.Add(drData)
If Me.DataSet11.HasChanges = True Then
SqlDataAdapter1.Update(DataSet11)
End If
Catch ex As Exception
MessageBox.Show("数据添加失败!")
End Try
End Sub |
|