回复 4楼 sywzs
Dim sqlstr As String
Dim strConnect As String = "data source=FG-C99768EB468F\SQLEXPRESS;integrated security = sspi;initial catalog=高校田径运动会"
Dim sqlConnectionl As SqlClient.SqlConnection
sqlConnectionl = New System.Data.SqlClient.SqlConnection(strConnect)
sqlConnectionl.Open()
Dim cmd As New SqlClient.SqlCommand()
cmd.Connection = sqlConnectionl
If TextBox5.Text = "" Or TextBox6.Text = "" Then
MessageBox.Show("比赛成绩和得分不能为空!", "错误提示")
Else
= CommandType.Text
= "select bscj from jscjb where ydybh ='" + TextBox1.Text + "'"
Dim mydatareader As SqlDataReader = cmd.ExecuteReader
Do While (mydatareader.Read())
TextBox5.Text = mydatareader.GetString(0)
Loop
If TextBox6.Text <> "" Then
MsgBox("该运动员成绩已经存在" + Chr(10) + Chr(13) + "请确认输入的运动员编号", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "错误提示")
TextBox5.Text = ""
TextBox6.Text = ""
Else
sqlstr = "insert into jscjb(ydybh,xymc,name ,xmmc,bscj,df,student_no) values( '" + TextBox1.Text + "','" + TextBox2.Text _
+ "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "')"
= sqlstr
cmd.ExecuteNonQuery()
MessageBox.Show("插入成功!", "正确提示")
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
End If
End If
sqlConnectionl.Close()
End Sub