我有个vb.net程序,其中别的添加功能都好用,只有学生信息添加不好用,请教怎么弄??
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