VB2010写人事系统,添加新记录时候,提示编号不能为空,请帮我看看
调试时,点击新建一条记录后,安保存就提示 "column 编号 does not allow nulls"Imports System.Text
Imports System.Windows.Forms.SaveFileDialog
Imports System.Data.SqlClient
Public Class frmbianjidangan
Dim bmdata As BindingManagerBase
Private Sub settextboxfalse()
DateTimePicker1.Enabled = False
txtbianhao.Enabled = False
txtxingming.Enabled = False
txtbumen.Enabled = False
cmbxingbie.Enabled = False
cmbhunyin.Enabled = False
txtminzhu.Enabled = False
cmbzhengzhi.Enabled = False
txtshenfenzhenghao.Enabled = False
txthukou.Enabled = False
txtjiguan.Enabled = False
txtshebaohao.Enabled = False
txt易做图.Enabled = False
txtdianhua.Enabled = False
cmbxueli.Enabled = False
txtzhuanye.Enabled = False
txtbiyexuexiao.Enabled = False
End Sub
Private Sub settextboxtrue()
DateTimePicker1.Enabled = True
txtbianhao.Enabled = True
txtxingming.Enabled = True
txtbumen.Enabled = True
cmbxingbie.Enabled = True
cmbhunyin.Enabled = True
txtminzhu.Enabled = True
cmbzhengzhi.Enabled = True
txtshenfenzhenghao.Enabled = True
txthukou.Enabled = True
txtjiguan.Enabled = True
txtshebaohao.Enabled = True
txt易做图.Enabled = True
txtdianhua.Enabled = True
cmbxueli.Enabled = True
txtzhuanye.Enabled = True
txtbiyexuexiao.Enabled = True
End Sub
Private Sub frmbianjidangan_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SqlDataAdapter1.Fill(DataSet31, "yuangongdangan")
bmdata = BindingContext(DataSet31, "yuangongdangan")
settextboxfalse()
End Sub
Private Sub updatedatasoure(ByVal changedrows As DataSet)
Try
If (Not (changedrows) Is Nothing) Then
SqlConnection1.Open()
SqlDataAdapter1.Update(changedrows)
End If
Catch updateexception As System.Exception
Throw updateexception
Finally
SqlConnection1.Close()
End Try
End Sub
Private Sub updatedataset()
Dim datasetchanges As DataSet
bmdata.EndCurrentEdit()
datasetchanges = CType(DataSet31.GetChanges, DataSet)
If (Not (datasetchanges) Is Nothing) Then
Try
updatedatasoure(datasetchanges)
DataSet31.Merge(datasetchanges)
DataSet31.AcceptChanges()
Catch exupdate As System.Exception
Throw (exupdate)
End Try
End If
End Sub
Private Sub butadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butadd.Click
settextboxtrue()
DateTimePicker1.Text = Today
Try
bmdata.EndCurrentEdit()
bmdata.AddNew()
Catch exadd As System.Exception
MessageBox.Show(exadd.Message)
End Try
End Sub
Private Sub butmodify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butmodify.Click
settextboxtrue()
txtbianhao.Focus()
End Sub
Private Sub butsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butsave.Click
Try
updatedataset()
Catch exupdate As System.Exception
MessageBox.Show(exupdate.Message)
End Try
End Sub
Private Sub butdel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butdel.Click
If MessageBox.Show("真的要删除吗?请确认", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) = Windows.Forms.DialogResult.Yes Then
If bmdata.Count > 0 Then
DataSet31.Tables("yuangangdangan").Rows(bmdata.Position).Delete()
If DataSet31.HasChanges = True Then
Dim dschild As DataSet = DataSet31.GetChanges
SqlDataAdapter1.Update(dschild)
End If
End If
End If
End Sub
Private Sub butfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butfirst.Click
bmdata.Position = 0
End Sub
Private Sub butnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butnext.Click
If bmdata.Position = (DataSet31.Tables("yanggongdangan").Rows.Count - 1) Then
MessageBox.Show("已是最后一条记录", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
bmdata.Position = (bmdata.Position + 1)
End If
End Sub
Private Sub butprev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butprev.Click
If bmdata.Position = 0 Then
MessageBox.Show("已经是第一条记录", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
bmdata.Position = (bmdata.Position - 1)
End If
End Sub
Private Sub butlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butlast.Click
bmdata.Position = (DataSet31.Tables("yuangongdangan").Rows.Count - 1)
End Sub
Private Sub butexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butexit.Click
Me.Close()
End Sub
End Class --------------------编程问答-------------------- 你的用户编号是什么规则啊?设置你的数据库,编号字段为自动增加的字段,选择是否标识为true --------------------编程问答-------------------- 谢谢你的解答,我没有设定自动增加字段规则,编号字段标识规范设定为“否” --------------------编程问答-------------------- 不允许空,又不给他赋值,当然出错了哦 --------------------编程问答-------------------- 是咯。。。。 --------------------编程问答-------------------- 如果编号字段为主键,那么是不允许为null的,记得一定要给编号赋值
如果不是主键,那么在设计表结构的时候记得把编号字段的“允许空”勾上
补充:.NET技术 , VB.NET