facing problem while executing vb.net query

前端 未结 7 975
情深已故
情深已故 2020-12-12 07:24
Dim con As SqlConnection
        con = New SqlConnection(\"server=chinna; uid=sa; pwd=136018@h; database=icms\")
        con.Open()
        Dim cmd As SqlCommand
            


        
相关标签:
7条回答
  • 2020-12-12 08:05

    You are missing the DataSource assignment.

    Add GridView1.DataSource = rdr before you call DataBind.

    Your If block should look like:

    If rdr.Read() Then  
     GridView1.Visible = True             
     GridView1.DataSource = rdr
     GridView1.DataBind()           
    End If 
    
    0 讨论(0)
  • 2020-12-12 08:09

    Should be

    cmd = New SqlCommand("select pass from personal where idno='" & TextBox1.Text & "'", con)
    

    beyond that code seems for ASP.net. We can not execute MsgBox in VB.net that can appear on client browser.

    0 讨论(0)
  • 2020-12-12 08:10

    What is your error or are you just getting a null for rdr?

    I don't see an outpout paramenter. You need one. You only have an input parameter.

    0 讨论(0)
  • 2020-12-12 08:15

    use HasRows on rdr and set DataSourcefor GridView1

        Dim rdr As SqlDataReader
        rdr = cmd.ExecuteReader()
        If rdr.HasRows Then
            GridView1.Visible = True
            GridView1.DataSource = rdr
            GridView1.DataBind()
        End If
    
    0 讨论(0)
  • 2020-12-12 08:16

    Use ExecuteScalar instead of ExecuteReader.

    Dim password As String
    password = cmd.ExecuteScalar.ToString()
    

    FYI, storing passwords in plain text and comparing like this is VERY bad practice. You should be encrypting the passwords with some one-way salted encryption and then doing the same on verification then comparing the encrypted values.

    0 讨论(0)
  • 2020-12-12 08:21

    You need to use parameters in your query:

    cmd = New SqlCommand("select pass from personal where idno=@param", con)
    cmd.Parameters.AddWithValue("param", TextBox1.Text);
    
    0 讨论(0)
提交回复
热议问题