寻求帮助VB2008列""不能为空值
我在系统里输入完信息后,单击保存就会出现列""不允许空值.但是删除这个功能是可以实现.帮忙解决啊不胜感激!!!!看是不是代码有问题还是数据库的设置????界面如下:
代码如下:
Imports System.Text
Imports System.Windows.Forms.SaveFileDialog
Imports System.Data.SqlClient '引入提供程序命名空间
Public Class Frmyewuyuanxinxi
Dim bmdata As BindingManagerBase '定义一个公有变量
Private Sub settextboxfalse() '设置捆绑的控件都不可用
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox3.Enabled = False
ComboBox1.Enabled = False
End Sub
Private Sub settextboxtrue() '设置捆绑的控件都可用
TextBox1.Enabled = True
TextBox2.Enabled = True
TextBox3.Enabled = True
ComboBox1.Enabled = True
End Sub
Private Sub Frmyewuyuanxinxi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SqlDataAdapter1.Fill(DataSet41, "业务员信息") '把从数据源读出的表 员工档案的记录数据填充到数据集DataSet41中
bmdata = BindingContext(DataSet41, "业务员信息") '用BindingContext类的构造函数来获得CurrencyManager对象
'让控件变的不可以接受数据的输入
settextboxfalse()
Label6.Text = DataSet41.Tables("业务员信息").Rows.Count().ToString & " 位业务员"
End Sub
Private Sub updatedatasource(ByVal changedrows As DataSet) '更新数据源的自定义过程
Try
If (Not (changedrows) Is Nothing) Then
SqlConnection1.Open()
SqlDataAdapter1.Update(changedrows) '把数据集changedrows对象中的数据更新到数据源
End If
Catch updateexception As System.Exception
Throw updateexception
Finally
SqlConnection1.Close()
End Try
End Sub
Public Sub updatedataset() '更新数据集自定义过程
Dim datasetchanges As DataSet '创建一个新数据集来保存对主数据集所做的更改
bmdata.EndCurrentEdit() '停止当前的任何编辑
datasetchanges = CType(DataSet41.GetChanges, DataSet) '获得对主数据的更改
If (Not (datasetchanges) Is Nothing) Then '检查是否做了任何更改
Try
updatedatasource(datasetchanges)
DataSet41.Merge(datasetchanges)
DataSet41.AcceptChanges()
Catch exupdate As System.Exception
Throw (exupdate)
End Try
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
settextboxtrue()
Try
bmdata.EndCurrentEdit()
bmdata.AddNew()
Catch exadd As System.Exception
MessageBox.Show(exadd.Message)
End Try
TextBox1.Focus()
Button1.Enabled = False
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
settextboxtrue() '控件变的可用
TextBox1.Focus() '获得焦点
End Sub
Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
If MessageBox.Show("真的要删除吗?请确认", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) = Windows.Forms.DialogResult.Yes Then
If bmdata.Count > 0 Then
DataSet41.Tables("业务员信息").Rows(bmdata.Position).Delete()
'删除后记录往后移一条
If bmdata.Position = (DataSet41.Tables("业务员信息").Rows.Count - 1) Then
MessageBox.Show("已是最后一条记录", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
bmdata.Position = (bmdata.Position + 1)
End If
SqlDataAdapter1.Update(DataSet41)
End If
End If
Label6.Text = DataSet41.Tables("业务员信息").Rows.Count().ToString & " 位业务员"
End Sub
Private Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Try
updatedataset()
Catch exupdate As System.Exception
MessageBox.Show(exupdate.Message)
End Try
Button1.Enabled = True
settextboxfalse()
Label6.Text = DataSet41.Tables("业务员信息").Rows.Count().ToString & " 位业务员"
End Sub
Private Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click
Me.Close()
End Sub
Private Sub Button7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim SearchSQL As String
Try
SearchSQL = "SELECT * FROM 业务员信息 where 姓名='" + TextBox4.Text.Trim + "'" 'SQL语句字符串
DataSet41.Clear() '先清空DataSet41中的记录,再填充
Dim ad As New SqlDataAdapter(SearchSQL, myCnn)
ad.Fill(DataSet41, "业务员信息")
Catch
MsgBox("不存在该记录!", vbOKOnly + vbExclamation, "警告")
End Try
End Sub
End Class