Saturday, March 24, 2012

login from password error message

this code in

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 = @dotnet.itags.org.comp_username "

Dim Comm As New SqlClient.SqlCommand(SQL, conn)
Dim Param As New SqlClient.SqlParameter("@dotnet.itags.org.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 tableHi!

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:
"Data Source=mySqlServer;Integrated Security=SSPI;Initial Catalog=myDB"Now you got some kind of recursion going on there...Check here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlConnectionClassTopic.asp) 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
changed my code to this

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()
...try passing the connection object to your SqlCommand object...
Here's the whole thing from msdn (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconpopulatingdatasetfromdataadapter.asp):

Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;
Integrated Security=SSPI;Initial Catalog=northwind")

Dim selectCMD As SqlCommand = New SqlCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn)
selectCMD.CommandTimeout = 30

Dim custDA As SqlDataAdapter = New SqlDataAdapter
custDA.SelectCommand = selectCMD

nwindConn.Open()

Dim custDS As DataSet = New DataSet
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

0 comments:

Post a Comment