| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 776 人关注过本帖
标题:寻求帮助VB2008列""不能为空值
只看楼主 加入收藏
daireday
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-4-7
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
寻求帮助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
搜索更多相关主题的帖子: 不胜感激 数据库 空间 
2010-04-07 14:30
radley
Rank: 2
等 级:论坛游民
帖 子:9
专家分:59
注 册:2009-11-7
收藏
得分:20 
你最好把附件附上来

[url=http://uu3.]点这里进入VB精英论坛[/url]
2010-04-08 09:20
快速回复:寻求帮助VB2008列""不能为空值
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017524 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved