【发布时间】:2016-03-20 13:02:11
【问题描述】:
我有一个名为“MyTable”的表。当“ID3”列是指定值时,我想读取“Active3”列。但我收到此错误:不存在数据时尝试读取无效。
Dim con1 As New SqlConnection(connectionString)
con1.Open()
Dim sql1 As String = String.Format("SELECT Active3,DateTime3,BuyDateTime3 FROM MyTable WHERE ID3='{0}'", Session("lblID8"))
Dim command1 As SqlCommand = New SqlCommand(sql1, con1)
Dim reader As SqlDataReader = command1.ExecuteReader
If reader.HasRows Then
Label4.Text = reader("Active3")
else
End If
con1.Close()
【问题讨论】:
-
准确的错误信息是...?
-
开始告诉我们错误。哦,尝试自己调试它。到目前为止,答案是“学习编程”。考虑到您提供的信息量,唯一可能的答案。
-
请:永远永远永远使用
WHERE ID3='{0}'之类的东西。您正在为最糟糕的攻击打开数据库。请查看如何使用 SQL 参数。 -
不要不使用
string.Format()创建SQL - 这会启用SQL注入!
标签: asp.net sql-server vb.net