| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1498 人关注过本帖
标题:无法向数据库添加数据问题,求教!!
取消只看楼主 加入收藏
liuyu123407
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-6-4
收藏
 问题点数:0 回复次数:0 
无法向数据库添加数据问题,求教!!
我的程序显示添加数据成功,可是数据库里却没有显示。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("学号不能为空")
        ElseIf TextBox6.Text = "" Then
            MsgBox("入学时间不能为空")
        ElseIf TextBox7.Text = "" Then
            MsgBox("学制不能为空")

        Else
            singleYanzheng()

        End If
    End Sub
    Sub singleYanzheng()
        Dim str As String

        str = "Data Source=7NNPKL9QYGFWVM2\SQLEXPRESS;Initial Catalog = Student;integrated Security=true"
        Dim con As New SqlConnection(str)
        con.Open()
        Dim sql As String = "select * from student_Info where student_ID='" & TextBox1.Text.ToString().Trim() & "' "

        Dim cmd As New SqlCommand(sql, con)
        Dim reader As SqlDataReader
        reader = cmd.ExecuteReader

        If reader.Read() = True Then



            MsgBox("该学号已存在")


        Else
            addStuInf()
            Dim p As Integer = MsgBox("添加成功!" + vbCrLf + "是否继续添加?", MsgBoxStyle.YesNo)
            If p = 7 Then
                Me.Hide()
            Else
                clear()
            End If

        End If
    End Sub
    Sub addStuInf()
        Dim str As String

        Dim sex As String
        If RadioButton1.Checked Then
            sex = "男"
        ElseIf RadioButton2.Checked Then
            sex = "女"
        Else
            sex = ""
        End If
        str = "Data Source=7NNPKL9QYGFWVM2\SQLEXPRESS;Initial Catalog = Student;integrated Security=true"
        Dim con As New SqlConnection(str)
        con.Open()

        Dim sql As String = "insert into student_Info (student_ID,student_Name,student_Sex,born_Date,depart_ID,class_NO,tele_Number,entr_Date,stu_Year,edu_bg,address,codeNo,zzmm,comment) values('" & TextBox1.Text.ToString().Trim() & "','" & TextBox2.Text.ToString().Trim() & " ','" & sex & " ','" & TextBox3.Text.ToString.Trim() & "','" & TextBox12.Text.ToString.Trim() & "','" & TextBox4.Text.ToString.Trim() & "','" & TextBox5.Text.ToString.Trim() & "','" & TextBox6.Text.ToString.Trim() & "','" & TextBox7.Text.ToString.Trim() & "','" & TextBox8.Text.ToString.Trim() & "','" & TextBox9.Text.ToString.Trim() & "','" & TextBox10.Text.ToString.Trim() & "','" & ComboBox1.Text.ToString.Trim() & "','" & TextBox11.Text.ToString.Trim() & "') "

        Dim cmd As New SqlCommand(sql, con)

        Try

            cmd.ExecuteNonQuery()

        Catch e As Exception

            Console.WriteLine(e.Message)

        End Try

        Console.WriteLine("Record Add")
    End Sub

    Private Sub RadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged
        Dim sex As String
        If RadioButton1.Checked Then
            sex = "男"
        ElseIf RadioButton2.Checked Then
            sex = "女"
        Else
            sex = ""

        End If

    End Sub
搜索更多相关主题的帖子: 数据库 
2014-06-04 11:59
快速回复:无法向数据库添加数据问题,求教!!
数据加载中...
 
   



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

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