cmd = New OleDbCommand(String.Format("select * from tbl_member where m_user='{0}' and m_code='{1}' ", tb_user.Text.Trim(), tb_code.Text.Trim()), c.pconn)
        Dim num As Integer
        num = cmd.ExecuteScalar()        If num Then
            Session("login") = tb_user.Text
        Else
            MsgBox("Error")
        End If
因为真的找不到vb.net的源码参考
我只能尽我能力了,别笑/.\
当登入键按了后就执行,寻找database先
然后再看看有没有这个会员,如果有,就给一个session
没有就弹出error
请问我应该加写什么东西来完善呢?
谢谢

解决方案 »

  1.   

    VB.NET 跟 C#是一家
    代码如下:(没调试可能有点小问题)Imports System.Data
    Imports System.Data.SqlClientPartial Public Class _Default
        Inherits System.Web.UI.Page    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        Dim dr As SqlDataReader = Nothing
            Dim cmd As SqlCommand = Nothing
            Dim conn As SqlConnection = New SqlConnection("你的连接字符串")
            Dim SqlStatement As String = String.Format( _
                                                       "select * from tbl_member where m_user='{0}' and m_code='{1}' " _
                                                       , tb_user.Text.Trim.Replace("'", "''"), tb_code.Text.Trim.Replace("'", "''") _
                                                       )
            Using (conn)
                If conn.State = ConnectionState.Closed Then conn.Open()
                cmd = New SqlCommand(SqlStatement, conn)
                dr = cmd.ExecuteReader
                If dr.Read Then
                    Session("login") = tb_user.Text
                Else
                    'MsgBox("Error")  <-- WebForm是不能使用这个的
                    Response.Write("<script type='text/javascript'>alert('没有该用户');</script>")
                End If
            End Using    End SubEnd Class
      

  2.   

     tb_user.Text.Trim.Replace("'", "''"), 
    关键就这句  防止sql注入
      

  3.   


    哦,只要username使用这句replace就能防止被注入了
    谢谢