vb.net,在textbox中显示sql server中查询到得数据
链接数控没有问题,只是不知道怎么把查询到得数据在textbox1中显示比如执行selectidfromuserlistwherepassword=1234语句的到结果为z...
链接数控没有问题,只是不知道怎么把查询到得数据在textbox1中显示
比如 执行 select id from userlist where password=1234 语句的到结果为zhangsan
怎么显示到textbox中呢
代码如下,textbox1处不会写,请告诉指点
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim conn As New System.Data.SqlClient.SqlConnection '创建一个新连接
conn.ConnectionString = "Data Source=FO525FSWNFBJVA8\SQLEXPRESS;Initial Catalog=MyDatabase;Persist Security Info=True;User ID=sa;Password=1234"
conn.Open()
Dim strSQL1 = "select id from userlist where password=1234"
ExeDMLSQL(strSQL1)
Dim Command As New System.Data.SqlClient.SqlCommand
Command.Connection = conn
Command.CommandType = CommandType.Text
Command.CommandText = strSQL1
'TextBox1.Text =查询到的数据 ,如zhangsan ,这里代码怎么写呢
TextBox1.Text = ExeDMLSQL(strSQL1)
conn.Close()
End Sub 展开
比如 执行 select id from userlist where password=1234 语句的到结果为zhangsan
怎么显示到textbox中呢
代码如下,textbox1处不会写,请告诉指点
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim conn As New System.Data.SqlClient.SqlConnection '创建一个新连接
conn.ConnectionString = "Data Source=FO525FSWNFBJVA8\SQLEXPRESS;Initial Catalog=MyDatabase;Persist Security Info=True;User ID=sa;Password=1234"
conn.Open()
Dim strSQL1 = "select id from userlist where password=1234"
ExeDMLSQL(strSQL1)
Dim Command As New System.Data.SqlClient.SqlCommand
Command.Connection = conn
Command.CommandType = CommandType.Text
Command.CommandText = strSQL1
'TextBox1.Text =查询到的数据 ,如zhangsan ,这里代码怎么写呢
TextBox1.Text = ExeDMLSQL(strSQL1)
conn.Close()
End Sub 展开
1个回答
展开全部
Dim strSQL1 = "select id from userlist where password=1234"
Cmd.CommandText = strSQL1
dim MyReader As SqlDataReader = Cmd.ExecuteReader
If MyReader.HasRows Then
While MyReader.Read
TextBox1.Text=MyReader("ID")
End While
End If
MyReader.Close()
Cmd.CommandText = strSQL1
dim MyReader As SqlDataReader = Cmd.ExecuteReader
If MyReader.HasRows Then
While MyReader.Read
TextBox1.Text=MyReader("ID")
End While
End If
MyReader.Close()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询