Scripter25
asked on
Please tell me what is wrong with this
Here is my code and below it is the error
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls. WebParts;
using System.Web.UI.HtmlControls ;
using System.Data.SqlClient;
public partial class employers_createneweuser : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string CGuid = "";
if ((string)Session["CompanyI D"] != "")
{
string Cid = (string)Session["CompanyID "]; // Request.QueryString["testi d"];
SqlConnection oConn1 = new SqlConnection("Data Source=.\\SQLEXPRESS;Attac hDbFilenam e=|DataDir ectory|\\j obs.mdf;In tegrated Security=True;User Instance=True");
SqlCommand cmd1 = new SqlCommand("usp_Get_Compan y_GUID", oConn1);
cmd1.CommandType = CommandType.StoredProcedur e;
SqlParameter workParam = new SqlParameter("@companyID", SqlDbType.NVarChar);
workParam.Value = Cid;
cmd1.Parameters.Add(workPa ram);
//string Cpass = (string)CompanyIDTxt.Text. ToString() ; // Request.QueryString["testi d"];
//SqlParameter passParam = new SqlParameter("@company_pas s", SqlDbType.NVarChar);
//passParam.Value = Cpass;
//cmd1.Parameters.Add(pass Param);
SqlParameter countParam = new SqlParameter("@validlogin" , SqlDbType.UniqueIdentifier );
countParam.Direction = ParameterDirection.Output;
//cmd.Parameters.Add(workP aram);
cmd1.Parameters.Add(countP aram);
oConn1.Open();
cmd1.ExecuteNonQuery();
// get the total number of products
CGuid = Convert.ToString(cmd1.Para meters["@v alidlogin" ].Value);
oConn1.Close();
}
System.Guid UID = System.Guid.NewGuid();
SqlConnection myConnection = new SqlConnection("Data Source=.\\SQLEXPRESS;Attac hDbFilenam e=|DataDir ectory|\\j obs.mdf;In tegrated Security=True;User Instance=True");
SqlCommand myCommand = new SqlCommand("InsertNewEUser ", myConnection);
myCommand.Connection = myConnection;
myCommand.CommandType = CommandType.StoredProcedur e;
SqlParameter UIDParam = new SqlParameter("@UID", SqlDbType.UniqueIdentifier );
UIDParam.Value = UID;
UIDParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(U IDParam);
SqlParameter UnameParam = new SqlParameter("@username", SqlDbType.NVarChar);
UnameParam.Value = (string)Session["UserName" ];
UnameParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(U nameParam) ;
SqlParameter UpassParam = new SqlParameter("@eupass", SqlDbType.NVarChar);
UpassParam.Value = (string)Session["Password" ];
UpassParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(U passParam) ;
SqlParameter emailParam = new SqlParameter("@email", SqlDbType.NVarChar);
emailParam.Value = (string)Session["Email"];
emailParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(e mailParam) ;
SqlParameter QuestionParam = new SqlParameter("@secQuestion ", SqlDbType.NVarChar);
QuestionParam.Value = (string)Session["Question" ];
QuestionParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(Q uestionPar am);
SqlParameter secAnswerParam = new SqlParameter("@secAnswer", SqlDbType.NVarChar);
secAnswerParam.Value = (string)Session["Answer"];
secAnswerParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(s ecAnswerPa ram);
SqlParameter CNParam = new SqlParameter("@company_nam e", SqlDbType.NVarChar);
CNParam.Value = (string)Session["CompanyID "];
CNParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(C NParam);
SqlParameter loc_cityParam = new SqlParameter("@loc_city", SqlDbType.NVarChar);
loc_cityParam.Value = "";
loc_cityParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(l oc_cityPar am);
SqlParameter loc_stateParam = new SqlParameter("@loc_state", SqlDbType.NVarChar);
loc_stateParam.Value = "";
loc_stateParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(l oc_statePa ram);
SqlParameter loc_zipParam = new SqlParameter("@loc_zip", SqlDbType.NVarChar);
loc_zipParam.Value = "";
loc_zipParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(l oc_zipPara m);
SqlParameter loc_area_codeParam = new SqlParameter("@loc_area_co de", SqlDbType.TinyInt);
loc_area_codeParam.Value = "";
loc_area_codeParam.Directi on = ParameterDirection.Input;
myCommand.Parameters.Add(l oc_area_co deParam);
SqlParameter loc_addressParam = new SqlParameter("@loc_address ", SqlDbType.NVarChar);
loc_addressParam.Value = "";
loc_addressParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(l oc_address Param);
SqlParameter company_guidParam = new SqlParameter("@company_gui d", SqlDbType.UniqueIdentifier );
company_guidParam.Value = CGuid;
company_guidParam.Directio n = ParameterDirection.Input;
myCommand.Parameters.Add(c ompany_gui dParam);
SqlParameter divisionParam = new SqlParameter("@division", SqlDbType.SmallInt);
divisionParam.Value = "";
divisionParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(d ivisionPar am);
myConnection.Open();
myCommand.ExecuteNonQuery( );
myCommand.Connection.Close ();
}
}
Failed to convert parameter value from a String to a Byte.
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 124:
Line 125: myConnection.Open();
Line 126: myCommand.ExecuteNonQuery( );
Line 127: myCommand.Connection.Close ();
Line 128:
Source File: c:\Documents and Settings\Scott\My Documents\Visual Studio 2005\WebSites\jobsite\empl oyers\crea teneweuser .aspx.cs Line: 126
Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Number.StringToNumb er(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2753507
System.Number.ParseInt32(S tring s, NumberStyles style, NumberFormatInfo info) +102
System.Byte.Parse(String s, NumberStyles style, NumberFormatInfo info) +22
System.String.System.IConv ertible.To Byte(IForm atProvider provider) +43
System.Convert.ChangeType( Object value, Type conversionType, IFormatProvider provider) +2562420
System.Data.SqlClient.SqlP arameter.C oerceValue (Object value, MetaType destinationType) +842
[FormatException: Failed to convert parameter value from a String to a Byte.]
System.Data.SqlClient.SqlP arameter.C oerceValue (Object value, MetaType destinationType) +903
System.Data.SqlClient.SqlP arameter.G etCoercedV alue() +58
System.Data.SqlClient.SqlP arameter.V alidate(In t32 index) +194
System.Data.SqlClient.SqlC ommand.Set UpRPCParam eters(_Sql RPC rpc, Int32 startCount, Boolean inSchema, SqlParameterCollection parameters) +153
System.Data.SqlClient.SqlC ommand.Bui ldRPC(Bool ean inSchema, SqlParameterCollection parameters, _SqlRPC& rpc) +107
System.Data.SqlClient.SqlC ommand.Run ExecuteRea derTds(Com mandBehavi or cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1118
System.Data.SqlClient.SqlC ommand.Run ExecuteRea der(Comman dBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334
System.Data.SqlClient.SqlC ommand.Int ernalExecu teNonQuery (DbAsyncRe sult result, String methodName, Boolean sendToPipe) +407
System.Data.SqlClient.SqlC ommand.Exe cuteNonQue ry() +149
employers_createneweuser.P age_Load(O bject sender, EventArgs e) in c:\Documents and Settings\Scott\My Documents\Visual Studio 2005\WebSites\jobsite\empl oyers\crea teneweuser .aspx.cs:1 26
System.Web.Util.CalliHelpe r.EventArg FunctionCa ller(IntPt r fp, Object o, Object t, EventArgs e) +31
System.Web.Util.CalliEvent HandlerDel egateProxy .Callback( Object sender, EventArgs e) +68
System.Web.UI.Control.OnLo ad(EventAr gs e) +88
System.Web.UI.Control.Load Recursive( ) +74
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +3037
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
using System.Web.UI.HtmlControls
using System.Data.SqlClient;
public partial class employers_createneweuser : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string CGuid = "";
if ((string)Session["CompanyI
{
string Cid = (string)Session["CompanyID
SqlConnection oConn1 = new SqlConnection("Data Source=.\\SQLEXPRESS;Attac
SqlCommand cmd1 = new SqlCommand("usp_Get_Compan
cmd1.CommandType = CommandType.StoredProcedur
SqlParameter workParam = new SqlParameter("@companyID",
workParam.Value = Cid;
cmd1.Parameters.Add(workPa
//string Cpass = (string)CompanyIDTxt.Text.
//SqlParameter passParam = new SqlParameter("@company_pas
//passParam.Value = Cpass;
//cmd1.Parameters.Add(pass
SqlParameter countParam = new SqlParameter("@validlogin"
countParam.Direction = ParameterDirection.Output;
//cmd.Parameters.Add(workP
cmd1.Parameters.Add(countP
oConn1.Open();
cmd1.ExecuteNonQuery();
// get the total number of products
CGuid = Convert.ToString(cmd1.Para
oConn1.Close();
}
System.Guid UID = System.Guid.NewGuid();
SqlConnection myConnection = new SqlConnection("Data Source=.\\SQLEXPRESS;Attac
SqlCommand myCommand = new SqlCommand("InsertNewEUser
myCommand.Connection = myConnection;
myCommand.CommandType = CommandType.StoredProcedur
SqlParameter UIDParam = new SqlParameter("@UID", SqlDbType.UniqueIdentifier
UIDParam.Value = UID;
UIDParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(U
SqlParameter UnameParam = new SqlParameter("@username", SqlDbType.NVarChar);
UnameParam.Value = (string)Session["UserName"
UnameParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(U
SqlParameter UpassParam = new SqlParameter("@eupass", SqlDbType.NVarChar);
UpassParam.Value = (string)Session["Password"
UpassParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(U
SqlParameter emailParam = new SqlParameter("@email", SqlDbType.NVarChar);
emailParam.Value = (string)Session["Email"];
emailParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(e
SqlParameter QuestionParam = new SqlParameter("@secQuestion
QuestionParam.Value = (string)Session["Question"
QuestionParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(Q
SqlParameter secAnswerParam = new SqlParameter("@secAnswer",
secAnswerParam.Value = (string)Session["Answer"];
secAnswerParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(s
SqlParameter CNParam = new SqlParameter("@company_nam
CNParam.Value = (string)Session["CompanyID
CNParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(C
SqlParameter loc_cityParam = new SqlParameter("@loc_city", SqlDbType.NVarChar);
loc_cityParam.Value = "";
loc_cityParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(l
SqlParameter loc_stateParam = new SqlParameter("@loc_state",
loc_stateParam.Value = "";
loc_stateParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(l
SqlParameter loc_zipParam = new SqlParameter("@loc_zip", SqlDbType.NVarChar);
loc_zipParam.Value = "";
loc_zipParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(l
SqlParameter loc_area_codeParam = new SqlParameter("@loc_area_co
loc_area_codeParam.Value = "";
loc_area_codeParam.Directi
myCommand.Parameters.Add(l
SqlParameter loc_addressParam = new SqlParameter("@loc_address
loc_addressParam.Value = "";
loc_addressParam.Direction
myCommand.Parameters.Add(l
SqlParameter company_guidParam = new SqlParameter("@company_gui
company_guidParam.Value = CGuid;
company_guidParam.Directio
myCommand.Parameters.Add(c
SqlParameter divisionParam = new SqlParameter("@division", SqlDbType.SmallInt);
divisionParam.Value = "";
divisionParam.Direction = ParameterDirection.Input;
myCommand.Parameters.Add(d
myConnection.Open();
myCommand.ExecuteNonQuery(
myCommand.Connection.Close
}
}
Failed to convert parameter value from a String to a Byte.
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 124:
Line 125: myConnection.Open();
Line 126: myCommand.ExecuteNonQuery(
Line 127: myCommand.Connection.Close
Line 128:
Source File: c:\Documents and Settings\Scott\My Documents\Visual Studio 2005\WebSites\jobsite\empl
Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Number.StringToNumb
System.Number.ParseInt32(S
System.Byte.Parse(String s, NumberStyles style, NumberFormatInfo info) +22
System.String.System.IConv
System.Convert.ChangeType(
System.Data.SqlClient.SqlP
[FormatException: Failed to convert parameter value from a String to a Byte.]
System.Data.SqlClient.SqlP
System.Data.SqlClient.SqlP
System.Data.SqlClient.SqlP
System.Data.SqlClient.SqlC
System.Data.SqlClient.SqlC
System.Data.SqlClient.SqlC
System.Data.SqlClient.SqlC
System.Data.SqlClient.SqlC
System.Data.SqlClient.SqlC
employers_createneweuser.P
System.Web.Util.CalliHelpe
System.Web.Util.CalliEvent
System.Web.UI.Control.OnLo
System.Web.UI.Control.Load
System.Web.UI.Page.Process
--------------------------
it looks like you are passing in a string that is meant to be stored in a number field in the database, but it is unable to convert that string to a number (possibly aplha chars in it?)
ASKER
Thats the thing is I dont see where that could be here is even my stored procedure that I am using
@UID uniqueidentifier,
@user_name nvarchar(50),
@eupass nvarchar(125),
@email nvarchar(50),
@secQuestion nvarchar(50),
@secAnswer nvarchar(50),
@company_name nvarchar(50),
@loc_city nvarchar(25),
@loc_state nvarchar(15),
@loc_zip nvarchar(5),
@loc_area_code tinyint,
@loc_address nvarchar(50),
@company_guid uniqueidentifier,
@division smallint
AS
SET IDENTITY_INSERT jobs.dbo.employer_main ON
INSERT INTO employer_main
(UID, username, eupass, email,
secQuestion , secAnswer,company_name,loc _city, loc_state,loc_zip,
loc_area_code,loc_address, company_guid,division)
VALUES
(@UID, @user_name, @eupass,@email,
@secQuestion , @secAnswer,@company_name,@ loc_city, @loc_state,@loc_zip,
@loc_area_code,@loc_addres s, @company_guid,@division)
@UID uniqueidentifier,
@user_name nvarchar(50),
@eupass nvarchar(125),
@email nvarchar(50),
@secQuestion nvarchar(50),
@secAnswer nvarchar(50),
@company_name nvarchar(50),
@loc_city nvarchar(25),
@loc_state nvarchar(15),
@loc_zip nvarchar(5),
@loc_area_code tinyint,
@loc_address nvarchar(50),
@company_guid uniqueidentifier,
@division smallint
AS
SET IDENTITY_INSERT jobs.dbo.employer_main ON
INSERT INTO employer_main
(UID, username, eupass, email,
secQuestion , secAnswer,company_name,loc
loc_area_code,loc_address,
VALUES
(@UID, @user_name, @eupass,@email,
@secQuestion , @secAnswer,@company_name,@
@loc_area_code,@loc_addres
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.