【发布时间】:2021-11-04 00:53:44
【问题描述】:
Dim SiparisOnayi As String
Dim SiparisDurumu As String
Dim SiparisIli As String
Dim SiparisOdemeYontemi As String
Dim SiparisKargoFirmasi As String
Dim SiparisSatisKanali As String
Dim a1, a2, a3, a4, a5, a6, a7, soncom As String
If ComboBox1.Text = Nothing Then
a1 = Nothing
Else
SiparisOnayi = ComboBox1.Text
a1 = " and Siparis_Onay = SiparisOnayi"
End If
If ComboBox2.Text = Nothing Then
a2 = Nothing
Else
SiparisDurumu = ComboBox2.Text
a2 = " and Siparis_Durumu = SiparisDurumu "
End If
If ComboBox3.Text = Nothing Then
a3 = Nothing
Else
SiparisIli = ComboBox3.Text
a3 = " and Musteri_IL = SiparisIli "
End If
If ComboBox4.Text = Nothing Then
a4 = Nothing
Else
a4 = " and Kullanici_Kodu = SiparisKullanicisi"
End If
If ComboBox5.Text = Nothing Then
a5 = Nothing
Else
SiparisOdemeYontemi = ComboBox5.Text
a5 = " and Odeme_Yontemi = SiparisOdemeYontemi"
End If
If ComboBox6.Text = Nothing Then
a6 = Nothing
Else
SiparisKargoFirmasi = ComboBox6.Text
a6 = " and Kargo_Adi = SiparisKargoFirmasi"
End If
If ComboBox7.Text = Nothing Then
a7 = Nothing
Else
SiparisSatisKanali = ComboBox7.Text
a7 = " and Satis_Kanali = SiparisSatisKanali"
End If
soncom = "SELECT * FROM `Siparisler` WHERE `Siparis_Tarihi` BETWEEN @d1 and @d2" & a1 & a2 & a3 & a4 & a5 & a6 & a7 & ", connection"
Try
Dim command As New MySqlCommand(soncom)
command.Parameters.Add("@d1", MySqlDbType.DateTime).Value = DateTimePicker2.Value
command.Parameters.Add("@d2", MySqlDbType.DateTime).Value = DateTimePicker3.Value
Dim table As New DataTable
Dim adapter As New MySqlDataAdapter(command)
adapter.Fill(table)
DataGridView1.DataSource = table
Label12.Text = "Toplam " & table.Rows.Count & " Kayıt bulundu ve gösteriliyor."
myconnection.close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
错误:填充:SelectCommand 连接属性尚未初始化
如何修复我的代码?
【问题讨论】:
-
这看起来很可怕——容易受到 sql 注入问题的影响。
-
, connection不应该是soncom字符串的一部分。它应该是命令的一部分:Dim command As New MySqlCommand(soncom, connection) -
另外,在谈到程序代码时,“code”的复数形式仍然只是“code”,而不是“codes”。
标签: vb.net