Results 1 to 4 of 4

Thread: login from password error message

  1. #1

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    login from password error message

    this code in

    Code:
     Dim conn As New SqlClient.SqlConnection("select * from tb_comp_login", conn)
            Dim SQL As String
    
            SQL = "SELECT comp_password "
            SQL &= "FROM tb_comp_login "
            SQL &= "WHERE comp_username = @comp_username "
    
            Dim Comm As New SqlClient.SqlCommand(SQL, conn)
            Dim Param As New SqlClient.SqlParameter("@comp_username", SqlDbType.VarChar)
            Param.Direction = ParameterDirection.Input
            Param.Value = Username
    
            Comm.Parameters.Add(Param)
    
            Dim da As New SqlClient.SqlDataAdapter(Comm)
            Dim dt As New DataTable
    
            da.Fill(dt)
    
            conn.Close()
            conn.Dispose()
    
            Dim Validated As Boolean
    
            If dt.Rows.Count > 0 Then
                Validated = (dt.Rows.Item(0).Item("Password").ToString = Username)
            End If
    
            Return Validated
    FORMAT OF THE INITIALIZATION STRING DOES NOT CONFORM TO SPECIFICATION STARTING AT 0

    the problem line seems to be dim conn as new sqlclient.sqlconnection("select..

    where should i set up my connection to the databse as this connects to the table
    Last edited by d2005; Sep 4th, 2005 at 09:47 AM.

  2. #2
    Junior Member Sami Antero's Avatar
    Join Date
    Jun 2005
    Location
    Helsinki, Finland
    Posts
    16

    Re: login from password error message

    Hi!

    There are two overloads for SqlConnections constructors, the other is the non-parametric New() and the other with (connectionString as String). You should not try to pass a SQL statement to your connection object.
    The connection string you need to pass for the connection object would be formatted something like this:
    VB Code:
    1. "Data Source=mySqlServer;Integrated Security=SSPI;Initial Catalog=myDB"
    Now you got some kind of recursion going on there...Check here for examples
    Remove the select statement from your sqlconnection object initialization and pass only the connection string to it and you should be allright.

    tsami
    Last edited by Sami Antero; Sep 5th, 2005 at 05:02 AM. Reason: typos
    Sami Antero
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    no smileys, no funky certificates. Sorry.

  3. #3

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    Re: login from password error message

    changed my code to this

    Code:
     Dim oSQLConn As SqlConnection = New SqlConnection
    
            oSQLConn.ConnectionString = "Data Source=(local);" & _
                   "Initial Catalog=TaT;" & _
                   "Integrated Security=SSPI"
            oSQLConn.Open()
    
            Dim conn As New SqlClient.SqlConnection
            Dim SQL As String
    
            SQL = "SELECT comp_password "
            SQL &= "FROM tb_comp_login "
            SQL &= "WHERE comp_username = @comp_username "
    
            Dim Comm As New SqlClient.SqlCommand(SQL, conn)
            Dim Param As New SqlClient.SqlParameter("@comp_username", SqlDbType.VarChar)
            Param.Direction = ParameterDirection.Input
            Param.Value = Username
    
            Comm.Parameters.Add(Param)
    
            Dim da As New SqlClient.SqlDataAdapter(Comm)
            Dim dt As New DataTable
    
            da.Fill(dt)
    
            conn.Close()
            conn.Dispose()
    
            Dim Validated As Boolean
    
            If dt.Rows.Count > 0 Then
                Validated = (dt.Rows.Item(0).Item("Password").ToString = Username)
            End If
    
            Return Validated
    now i get the error of
    The ConnectionString property has not been initialized.

    Line 88: Dim dt As New DataTable
    Line 89:
    Line 90: da.Fill(dt)
    Line 91:
    Line 92: conn.Close()

  4. #4
    Junior Member Sami Antero's Avatar
    Join Date
    Jun 2005
    Location
    Helsinki, Finland
    Posts
    16

    Re: login from password error message

    ...try passing the connection object to your SqlCommand object...
    Here's the whole thing from msdn:

    VB Code:
    1. Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;
    2. Integrated Security=SSPI;Initial Catalog=northwind")
    3.  
    4. Dim selectCMD As SqlCommand = New SqlCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn)
    5. selectCMD.CommandTimeout = 30
    6.  
    7. Dim custDA As SqlDataAdapter = New SqlDataAdapter
    8. custDA.SelectCommand = selectCMD
    9.  
    10. nwindConn.Open()
    11.  
    12. Dim custDS As DataSet = New DataSet
    13. custDA.Fill(custDS, "Customers")

    And populate a dataset object. You are now trying to populate a datatable, not a dataset. A dataset consists of datatables which you can then manipulate. Check the example above. That should help you!

    tsami
    Last edited by Sami Antero; Sep 6th, 2005 at 12:34 AM.
    Sami Antero
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    no smileys, no funky certificates. Sorry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width