当我点击搜索按钮,下面的代码将运行。代码中没有错误,但datagridview仅显示列名。查询是否有错误?VB.NET MYSQL Datagridview为空?
mySqlConn = New MySqlConnection
myCommand = New MySqlCommand
dt = New DataTable()
Try
If dt IsNot Nothing Then
dt.Dispose()
End If
If da IsNot Nothing Then
da.Dispose()
End If
If DataGridView1.DataSource IsNot Nothing Then
DataGridView1.DataSource = Nothing
End If
mySqlConn.ConnectionString = connStr
myCommand.CommandText = "Select * from createproject Where (FloatNumber = @floatNo OR @floatNo is Null) AND (DeveloperName = @devName OR @devName is Null) AND (DevelopmentType = @devType OR @devType is Null) AND (LotPt = @lotPt OR @lotPt is Null) AND (Mukim = @mukim OR @mukim is Null) AND (Daerah = @daerah OR @daerah is Null) AND (Negeri = @negeri OR @negeri is Null) AND (TempReference = @tempRef OR @tempRef is Null)"
myCommand.Connection = mySqlConn
mySqlConn.Open()
myCommand.Parameters.AddWithValue("@floatNo", TextBox3.Text.Trim())
myCommand.Parameters.AddWithValue("@devName", ComboBox6.Text.Trim())
myCommand.Parameters.AddWithValue("@devType", ComboBox7.Text.Trim())
myCommand.Parameters.AddWithValue("@lotPt", TextBox4.Text.Trim())
myCommand.Parameters.AddWithValue("@mukim", ComboBox8.Text.Trim())
myCommand.Parameters.AddWithValue("@daerah", ComboBox9.Text.Trim())
myCommand.Parameters.AddWithValue("@negeri", ComboBox10.Text.Trim())
myCommand.Parameters.AddWithValue("@tempRef", TextBox6.Text.Trim())
da = New MySqlDataAdapter(myCommand.ToString(), mySqlConn)
da.SelectCommand = myCommand
da.Fill(dt)
DataGridView1.DataSource = dt
da.Update(dt)
Catch ex As MySqlException
MsgBox(ex.ToString())
Finally
mySqlConn.Close()
mySqlConn.Dispose()
End Try
推断看看在http:// bobby- tables.com/ – William
@William是关于sql注入预防的吗?我已经做对了......? – Student
大概没有符合您的标准的记录。我们不应该真的需要解释这一点,但你应该改变你的查询使用一个条件,然后两个,等等。只要你没有得到你所期望的,你已经找到了问题。 – jmcilhinney