登录代码:
...........
Dim sqlcmd As New SqlCommand
sqlcmd.Connection = sqlconn
sqlcmd.CommandType = Data.CommandType.Text
sqlcmd.CommandText = "select name,password from admininfo where(name='" + TextBox1.Text + "' and password='" + TextBox2.Text + "')"
sqlconn.Open()
Dim sqldr As SqlDataReader
sqldr = sqlcmd.ExecuteReader
If sqldr.Read() Then
Response.Write("<script language=""vbscript"">alert:登录成功!</script>")无法显示:"登录成功!"?
Response.Redirect("register.aspx?name=" & TextBox1.Text & " & password=" & TextBox2.Text & "")
Else : Response.Redirect("errormsg.aspx")
End If
sqldr.Close()
sqlconn.Close()
将红色代码换成(听说这样能防止SQL注入):
sqlcmd.parameters("@name").value=textbox1.text
sqlcmd.parameters("@password").value=textbox2.text
sqlcmd.CommandText = "select name,password from admininfo where(name=@name)and (password=@password)
错误:此 SqlParameterCollection 中未包含带有 ParameterName“@name”的 SqlParameter
各位DX帮忙看一下,谢谢了!
------解决方案--------------------------------------------------------
- C# code
sqlcmd.CommandText = "select name,password from admininfo where (name=@name) and (password=@password)"cmd.Parameters.Add(new SqlParameter("@name", SqlDbType.NVarChar, 64))cmd.Parameters.Add(new SqlParameter("@password", SqlDbType.NVarChar, 128))sqlcmd.parameters("@name").value=textbox1.text sqlcmd.parameters("@password").value=textbox2.text
------解决方案--------------------------------------------------------
没有把@name添加进你sqlcommand参数里
new SqlParameter添加`
------解决方案--------------------------------------------------------
楼上正解~
改成Vb的就可以了~
------解决方案--------------------------------------------------------
SqlParameter sq =new SqlParameter(这里面是参数的总数)
------解决方案--------------------------------------------------------
在Vb.net使用参数与C#有所不同,vb.net可是先创建一个参数集实例,然后把参数集实例赋给command实例:
仿照下面的例子来做:
Dim sqlParameters(3) As SqlParameters
sqlParameter(0)= New SqlParameter("@description", Data.SqlDbType.VarChar)
sqlParameter(0).value="This is a picture"
sqlParameter(1)= New SqlParameter("@description", Data.SqlDbType.Image)
sqlParameter(1).value=content
sqlParameter(2)= New SqlParameter("@imagesize", Data.SqlDbType.Int)
sqlParameter(2).value=content.Length
sqlParameter(3)= New SqlParameter("@imagetype", Data.SqlDbType.NVarChar)
sqlParameter(3).value= obj.Extension
command.Parameters=sqlParameters
楼主在command的Parameters直接加入参数:sqlcmd.parameters("@name").value=textbox1.text 是不行的.