A
Andy G
I've been getting this error all day. Could someone please look at my
stored procedure and the code. I have a form that grabs and email address
the user types in, calls a stored procedure with an input parameter and an
output parameter, compared the email to a table and matches an ID in another
table to grab the Username. thanks for any helps guys/girls!
Andy
The error I am getting is @LOGIN_NAME' of type: String, the property Size
has an invalid size: 0
Here is my Stack Trace if it is any help:
[InvalidOperationException: Parameter 1: '@LOGIN_NAME' of type: String, the
property Size has an invalid size: 0]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +740
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +196
CFSPH.ForgotUsername.btnSubmit_Click(Object sender, ImageClickEventArgs
e) in
\\129.186.78.211\CFSPHDEV$\CFSPH\BRM\Authentication\ForgotUsername.aspx.vb:9
4
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +108
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.Ra
isePostBackEvent(String eventArgument) +69
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292
The stored procedure:
CREATE PROCEDURE dbo.stpCFSPH_GET_LOGINNAME
(
@EMAIL VARCHAR(30),
@LOGIN_NAME VARCHAR(255) OUTPUT
)
AS
SELECT @LOGIN_NAME = B.LOGIN_NAME
FROM dbo.tblCFSPH_PRSN A, dbo.tblCFSPH_LOGIN B
WHERE A.EMAIL = @EMAIL
AND A.PRSN_ID = B.PRSN_ID
The code behind the button:
'Instantiate Connection class
Dim getConn As New Connection
'Declare SQL info
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim myParameter As SqlParameter
Dim myDataReader As SqlDataReader
'Create connection and set connection string
myConnection = New SqlConnection(getConn.GetCnxString())
'Create a new command object
myCommand = New SqlCommand
'Set the properties of the command so that it uses our connection,
'our stored proc, and knows that its executing a stored proc
myCommand.Connection = myConnection
myCommand.CommandText = "stpCFSPH_GET_LOGINNAME"
myCommand.CommandType = CommandType.StoredProcedure
'Create input parameter @EMAIL, declare and set value
myParameter = myCommand.CreateParameter()
myParameter.ParameterName = "@EMAIL"
myParameter.Direction = ParameterDirection.Input
myParameter.SqlDbType = SqlDbType.VarChar
myParameter.Value = txtEmail.Text
'Add input parameter to command
myCommand.Parameters.Add(myParameter)
'Create output parameter
myParameter = myCommand.CreateParameter()
myParameter.ParameterName = "@LOGIN_NAME"
myParameter.Direction = ParameterDirection.Output
myParameter.SqlDbType = SqlDbType.VarChar
myParameter.Size = 255
'Add output parameter to command
myCommand.Parameters.Add(myParameter)
'myCommand.Parameters.Add("@EMAIL", SqlDbType.VarChar, 255)
'Open connection to the SQL server
myConnection.Open()
'Execute and no return due to output parameter
myCommand.ExecuteNonQuery()
txtReturn.Text = myCommand.Parameters("@LOGIN_NAME").Value
stored procedure and the code. I have a form that grabs and email address
the user types in, calls a stored procedure with an input parameter and an
output parameter, compared the email to a table and matches an ID in another
table to grab the Username. thanks for any helps guys/girls!
Andy
The error I am getting is @LOGIN_NAME' of type: String, the property Size
has an invalid size: 0
Here is my Stack Trace if it is any help:
[InvalidOperationException: Parameter 1: '@LOGIN_NAME' of type: String, the
property Size has an invalid size: 0]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +740
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +196
CFSPH.ForgotUsername.btnSubmit_Click(Object sender, ImageClickEventArgs
e) in
\\129.186.78.211\CFSPHDEV$\CFSPH\BRM\Authentication\ForgotUsername.aspx.vb:9
4
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +108
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.Ra
isePostBackEvent(String eventArgument) +69
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292
The stored procedure:
CREATE PROCEDURE dbo.stpCFSPH_GET_LOGINNAME
(
@EMAIL VARCHAR(30),
@LOGIN_NAME VARCHAR(255) OUTPUT
)
AS
SELECT @LOGIN_NAME = B.LOGIN_NAME
FROM dbo.tblCFSPH_PRSN A, dbo.tblCFSPH_LOGIN B
WHERE A.EMAIL = @EMAIL
AND A.PRSN_ID = B.PRSN_ID
The code behind the button:
'Instantiate Connection class
Dim getConn As New Connection
'Declare SQL info
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim myParameter As SqlParameter
Dim myDataReader As SqlDataReader
'Create connection and set connection string
myConnection = New SqlConnection(getConn.GetCnxString())
'Create a new command object
myCommand = New SqlCommand
'Set the properties of the command so that it uses our connection,
'our stored proc, and knows that its executing a stored proc
myCommand.Connection = myConnection
myCommand.CommandText = "stpCFSPH_GET_LOGINNAME"
myCommand.CommandType = CommandType.StoredProcedure
'Create input parameter @EMAIL, declare and set value
myParameter = myCommand.CreateParameter()
myParameter.ParameterName = "@EMAIL"
myParameter.Direction = ParameterDirection.Input
myParameter.SqlDbType = SqlDbType.VarChar
myParameter.Value = txtEmail.Text
'Add input parameter to command
myCommand.Parameters.Add(myParameter)
'Create output parameter
myParameter = myCommand.CreateParameter()
myParameter.ParameterName = "@LOGIN_NAME"
myParameter.Direction = ParameterDirection.Output
myParameter.SqlDbType = SqlDbType.VarChar
myParameter.Size = 255
'Add output parameter to command
myCommand.Parameters.Add(myParameter)
'myCommand.Parameters.Add("@EMAIL", SqlDbType.VarChar, 255)
'Open connection to the SQL server
myConnection.Open()
'Execute and no return due to output parameter
myCommand.ExecuteNonQuery()
txtReturn.Text = myCommand.Parameters("@LOGIN_NAME").Value