VB.NET实现sql查询问题

来源:百度知道 编辑:UC知道 时间:2024/05/31 13:35:44
我用VB连接到数据库实现了SQL查询,用的dr.read(),当dr.read()真的时候出现MSGBOX提示,当假的时候执行SQL的插入语句,怎样实现?
Dim sql As String = "select * from 学生基本信息表 where 学号='" & textbox1.Text & "'"
Dim searchsql As String = "insert into 学生基本信息表 values('"
Dim xh, name, sex, id, tel, address As String
Dim time As DateTime
If textbox1.Text = "" Or textbox2.Text = "" Then
MsgBox("该生信息不完整")
Else
conn.ConnectionString = "Data Source=ZX\SQLEXPRESS;Initial Catalog=studentMIS;Integrated Security=True"
conn.Open()
cmd.CommandText = sql
cmd.Connection = conn
sqlda.SelectCommand = cmd
Try
dr = cmd.ExecuteReader()
Do While dr.Read()
MsgBox("该生信息已存在")
Loop

实在看不下去了,
Const sql As String = "select * from 学生基本信息表 where 学号='" & textbox1.Text & "'"
Const searchsql As String = "insert into 学生基本信息表 values('"
Dim xh As String , name As String , sex As String , id As String , tel As String , address As String
Dim time As DateTime
Dim conn as new adodb.connection
dim ConnectionString as string

If textbox1.Text = "" Or textbox2.Text = "" Then
MsgBox "该生信息不完整"
Else
ConnectionString = "Data Source=ZX\SQLEXPRESS;Initial Catalog=studentMIS;Integrated Security=True"
conn.Open(ConnectionString)
cmd.CommandText = sql
cmd.Connection = conn
sqlda.SelectCommand = cmd
Try
dr = cmd.ExecuteReader()
Do While dr.Read()
MsgBox("该生信息已存在")
Loop
If dr.Read = False Then
xh = textbox1.Text
name = textbox2.Text
sex = cb1.SelectedItem <