 |
|
| .NET DotNet Forum Index » ASP.NET Forum » System.InvalidCastException was unhandled by user code... |
|
Page 1 of 1 |
|
| Author |
Message |
| Deven... |
Posted: Wed Jul 01, 2009 1:18 pm |
|
|
|
Guest
|
I have custom login.aspx page in which I am calling store procedure to verify
if user exist in database. For some reason, when I run application to test,
it will crash on following line with error message...
sqlLoginCheck.Parameters.Add("P")
Message="The SqlParameterCollection only accepts non-null SqlParameter type
objects, not String objects."
Below is exact code in my logincheck sub procedure.
Protected Sub LoginCheck()
Dim intResult As Integer
Dim conSqlConnection As SqlConnection = New
SqlConnection(ConfigurationManager.ConnectionStrings("SRConnectionString").ConnectionString)
Dim sqlLoginCheck As SqlCommand = New SqlCommand("uspCheckLogin",
conSqlConnection)
sqlLoginCheck.CommandType = Data.CommandType.StoredProcedure
sqlLoginCheck.CommandText = "uspCheckLogin"
sqlLoginCheck.Parameters.Add(" at (no spam) Username", Data.SqlDbType.NVarChar,
10).Value = txtUsername.Text
sqlLoginCheck.Parameters.Add(" at (no spam) Password", Data.SqlDbType.NVarChar,
10).Value = txtPassword.Text
Dim P As SqlParameter = New SqlParameter(" at (no spam) Result",
Data.SqlDbType.Int)
P.Direction = Data.ParameterDirection.Output
conSqlConnection.Open()
sqlLoginCheck.Parameters.Add("P")
sqlLoginCheck.ExecuteNonQuery()
intResult = Convert.ToInt32(sqlLoginCheck.Parameters(" at (no spam) Result").Value)
conSqlConnection.Close()
If intResult = 1 Then
Session("strUsername") = txtUsername.Text
Server.Transfer("success.aspx")
Else
Server.Transfer("Failed.aspx")
End If
End Sub
Any help in this matter would be appreciated.
Thanks,
Deven |
|
|
| Back to top |
|
|
|
| miher... |
Posted: Wed Jul 01, 2009 2:33 pm |
|
|
|
Guest
|
"Deven" <Deven at (no spam) discussions.microsoft.com> az alábbiakat írta a következő
üzenetben news:50442500-EBA5-4DB7-A733-388890C3A8E0 at (no spam) microsoft.com...
Quote: I have custom login.aspx page in which I am calling store procedure to
verify
if user exist in database. For some reason, when I run application to
test,
it will crash on following line with error message...
sqlLoginCheck.Parameters.Add("P")
Message="The SqlParameterCollection only accepts non-null SqlParameter
type
objects, not String objects."
Below is exact code in my logincheck sub procedure.
Protected Sub LoginCheck()
Dim intResult As Integer
Dim conSqlConnection As SqlConnection = New
SqlConnection(ConfigurationManager.ConnectionStrings("SRConnectionString").ConnectionString)
Dim sqlLoginCheck As SqlCommand = New SqlCommand("uspCheckLogin",
conSqlConnection)
sqlLoginCheck.CommandType = Data.CommandType.StoredProcedure
sqlLoginCheck.CommandText = "uspCheckLogin"
sqlLoginCheck.Parameters.Add(" at (no spam) Username", Data.SqlDbType.NVarChar,
10).Value = txtUsername.Text
sqlLoginCheck.Parameters.Add(" at (no spam) Password", Data.SqlDbType.NVarChar,
10).Value = txtPassword.Text
Dim P As SqlParameter = New SqlParameter(" at (no spam) Result",
Data.SqlDbType.Int)
P.Direction = Data.ParameterDirection.Output
conSqlConnection.Open()
sqlLoginCheck.Parameters.Add("P")
sqlLoginCheck.ExecuteNonQuery()
intResult =
Convert.ToInt32(sqlLoginCheck.Parameters(" at (no spam) Result").Value)
conSqlConnection.Close()
If intResult = 1 Then
Session("strUsername") = txtUsername.Text
Server.Transfer("success.aspx")
Else
Server.Transfer("Failed.aspx")
End If
End Sub
Any help in this matter would be appreciated.
Thanks,
Deven
Hi,
What the line < sqlLoginCheck.Parameters.Add("P") > does is trying to add
the string "P" as an sqlparameter, however what You would like to do is to
add the variable named P to the parameters collection using the line:
sqlLoginCheck.Parameters.Add(P)
(notice that there are no quotes around P)
-Zsolt |
|
|
| Back to top |
|
|
|
| Deven... |
Posted: Wed Jul 01, 2009 7:47 pm |
|
|
|
Guest
|
Thank you for your quick response. It resolved my problem.
Thanks,
Deven
"miher" wrote:
Quote:
"Deven" <Deven at (no spam) discussions.microsoft.com> az alábbiakat írta a következő
üzenetben news:50442500-EBA5-4DB7-A733-388890C3A8E0 at (no spam) microsoft.com...
I have custom login.aspx page in which I am calling store procedure to
verify
if user exist in database. For some reason, when I run application to
test,
it will crash on following line with error message...
sqlLoginCheck.Parameters.Add("P")
Message="The SqlParameterCollection only accepts non-null SqlParameter
type
objects, not String objects."
Below is exact code in my logincheck sub procedure.
Protected Sub LoginCheck()
Dim intResult As Integer
Dim conSqlConnection As SqlConnection = New
SqlConnection(ConfigurationManager.ConnectionStrings("SRConnectionString").ConnectionString)
Dim sqlLoginCheck As SqlCommand = New SqlCommand("uspCheckLogin",
conSqlConnection)
sqlLoginCheck.CommandType = Data.CommandType.StoredProcedure
sqlLoginCheck.CommandText = "uspCheckLogin"
sqlLoginCheck.Parameters.Add(" at (no spam) Username", Data.SqlDbType.NVarChar,
10).Value = txtUsername.Text
sqlLoginCheck.Parameters.Add(" at (no spam) Password", Data.SqlDbType.NVarChar,
10).Value = txtPassword.Text
Dim P As SqlParameter = New SqlParameter(" at (no spam) Result",
Data.SqlDbType.Int)
P.Direction = Data.ParameterDirection.Output
conSqlConnection.Open()
sqlLoginCheck.Parameters.Add("P")
sqlLoginCheck.ExecuteNonQuery()
intResult =
Convert.ToInt32(sqlLoginCheck.Parameters(" at (no spam) Result").Value)
conSqlConnection.Close()
If intResult = 1 Then
Session("strUsername") = txtUsername.Text
Server.Transfer("success.aspx")
Else
Server.Transfer("Failed.aspx")
End If
End Sub
Any help in this matter would be appreciated.
Thanks,
Deven
Hi,
What the line < sqlLoginCheck.Parameters.Add("P") > does is trying to add
the string "P" as an sqlparameter, however what You would like to do is to
add the variable named P to the parameters collection using the line:
sqlLoginCheck.Parameters.Add(P)
(notice that there are no quotes around P)
-Zsolt
|
|
|
| Back to top |
|
|
|
|
|
All times are GMT - 5 Hours
The time now is Tue Nov 24, 2009 7:26 pm
|
|