[英]List ms sql data in vb.net
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. 我该怎么做才能工作?请帮助,谢谢。
The problem is most likely the: 问题很可能是:
WHERE (SCHOOL='" & TextBox1.Text & "')" 在哪里(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. 如果忽略了基本安全性原则的公然无知(请立即阅读SQL注入),这是一个完整的比较。
My standard practice would be: 我的标准做法是:
Take the SQL and work it out in... SQL Manager. 使用SQL并在... SQL Manager中进行处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.