我正在尝试比较一个字符串(网络 ID)并使用 SQL Like 命令,返回受影响的行数(如果找到了用户名)但是在我的代码中我总是得到“-1”,我找不到原因,用户名是正确的,通过在 SQL Server Mgt 中运行查询在 SQL 表中找到。
Try
Dim Con As New SqlConnection
Con.ConnectionString = "Data Source=WCRDUSMJEMPR9\SQLEXPRESS;Initial Catalog=MicroDB;Integrated Security=True"
Con.Open()
Dim SQL2 As String
SQL2 = "SELECT * from MicroDB_Users WHERE Users LIKE '+@Usercheck+'"
Dim cmd2 As New SqlCommand(SQL2, Con)
cmd2.Parameters.AddWithValue("@Usercheck", TextBox1.Text)
Dim obj2 = cmd2.ExecuteNonQuery
Con.Close()
If obj2 > 0 Then
MsgBox(obj2)
Response.Redirect("~\ControlCharts\AddData_Control.aspx")
Label7_Control.Visible = False
Else
MsgBox(obj2)
Label7_Control.Text = ("You are not authorized to Add Data")
Label7_Control.Visible = True
End If
Catch ex As Exception
MsgBox(Err.Description)
如您所见,我正在使用 IF 来比较是否找到用户(受影响的 1 行)或未找到用户(受影响的 0 行)。