在 vb.net 中列出 ms sql 数据
我现在代码中没有错误,但它似乎不起作用。唯一有效的是当我尝试列出所有数据时。
但是当我尝试缩小要列出的数据范围时。我没有得到好的结果。这是我的代码:
If ComboBox1.SelectedItem = "School" Then
Dim connectionString As String = "Data Source=SENBONZAKURA\SQLEXPRESS;Initial Catalog=testing;User ID=SenbonZakura\Rew; Trusted_Connection=True;"
Dim selectCommand As String
Dim connection As New SqlConnection(connectionString)
selectCommand = "select * from student WHERE (SCHOOL='" & TextBox1.Text & "')"
Me.dataAdapter = New SqlDataAdapter(selectCommand, connection)
Dim commandBuilder As New SqlCommandBuilder(Me.dataAdapter)
Dim table As New DataTable()
Me.dataAdapter.Fill(table)
Me.BindingSource1.DataSource = table
Dim data As New DataSet()
DataGridView1.DataSource = Me.BindingSource1
END IF
上面的代码并不是全部。我省略了那些不相关的内容。我该怎么做才能完成这项工作?请帮忙,谢谢。
I got no errors in the code now, but it doesn't seem to work. The only thing that works is when I try to list all the data.
But when I try to narrow the data that is to be listed. I get no good results. Here is my code:
If ComboBox1.SelectedItem = "School" Then
Dim connectionString As String = "Data Source=SENBONZAKURA\SQLEXPRESS;Initial Catalog=testing;User ID=SenbonZakura\Rew; Trusted_Connection=True;"
Dim selectCommand As String
Dim connection As New SqlConnection(connectionString)
selectCommand = "select * from student WHERE (SCHOOL='" & TextBox1.Text & "')"
Me.dataAdapter = New SqlDataAdapter(selectCommand, connection)
Dim commandBuilder As New SqlCommandBuilder(Me.dataAdapter)
Dim table As New DataTable()
Me.dataAdapter.Fill(table)
Me.BindingSource1.DataSource = table
Dim data As New DataSet()
DataGridView1.DataSource = Me.BindingSource1
END IF
The code above is not the whole thing. I've omitted those that are not relevant. What do I do to make this work?Please help, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题很可能是:
WHERE (SCHOOL='" & TextBox1.Text & "')"
部分。如果忽略对基本安全原则的公然无知(有空时请阅读 SQL 注入),这是一个 我的标准做法
是:
使用 SQL 进行计算。 . SQL 管理器。
The problem is most likely the:
WHERE (SCHOOL='" & TextBox1.Text & "')"
part. Ifgnoring the blatant ignorance of basic securtiy principles (read up on SQL Injection when you ahve the moment), this is a full comparison.
My standard practice would be:
Take the SQL and work it out in... SQL Manager.