Link to home
Start Free TrialLog in
Avatar of Scripter25
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["CompanyID"] != "")

{

string Cid = (string)Session["CompanyID"]; // Request.QueryString["testid"];

SqlConnection oConn1 = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\jobs.mdf;Integrated Security=True;User Instance=True");

SqlCommand cmd1 = new SqlCommand("usp_Get_Company_GUID", oConn1);

cmd1.CommandType = CommandType.StoredProcedure;

SqlParameter workParam = new SqlParameter("@companyID", SqlDbType.NVarChar);

workParam.Value = Cid;

cmd1.Parameters.Add(workParam);

//string Cpass = (string)CompanyIDTxt.Text.ToString(); // Request.QueryString["testid"];

//SqlParameter passParam = new SqlParameter("@company_pass", SqlDbType.NVarChar);

//passParam.Value = Cpass;

//cmd1.Parameters.Add(passParam);

SqlParameter countParam = new SqlParameter("@validlogin", SqlDbType.UniqueIdentifier);

countParam.Direction = ParameterDirection.Output;

//cmd.Parameters.Add(workParam);

cmd1.Parameters.Add(countParam);

oConn1.Open();

cmd1.ExecuteNonQuery();

// get the total number of products

CGuid = Convert.ToString(cmd1.Parameters["@validlogin"].Value);

oConn1.Close();

}

System.Guid UID = System.Guid.NewGuid();

SqlConnection myConnection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\jobs.mdf;Integrated Security=True;User Instance=True");

SqlCommand myCommand = new SqlCommand("InsertNewEUser", myConnection);

myCommand.Connection = myConnection;

myCommand.CommandType = CommandType.StoredProcedure;

SqlParameter UIDParam = new SqlParameter("@UID", SqlDbType.UniqueIdentifier);

UIDParam.Value = UID;

UIDParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(UIDParam);

SqlParameter UnameParam = new SqlParameter("@username", SqlDbType.NVarChar);

UnameParam.Value = (string)Session["UserName"];

UnameParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(UnameParam);

SqlParameter UpassParam = new SqlParameter("@eupass", SqlDbType.NVarChar);

UpassParam.Value = (string)Session["Password"];

UpassParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(UpassParam);

SqlParameter emailParam = new SqlParameter("@email", SqlDbType.NVarChar);

emailParam.Value = (string)Session["Email"];

emailParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(emailParam);

SqlParameter QuestionParam = new SqlParameter("@secQuestion", SqlDbType.NVarChar);

QuestionParam.Value = (string)Session["Question"];

QuestionParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(QuestionParam);

SqlParameter secAnswerParam = new SqlParameter("@secAnswer", SqlDbType.NVarChar);

secAnswerParam.Value = (string)Session["Answer"];

secAnswerParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(secAnswerParam);

SqlParameter CNParam = new SqlParameter("@company_name", SqlDbType.NVarChar);

CNParam.Value = (string)Session["CompanyID"];

CNParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(CNParam);

SqlParameter loc_cityParam = new SqlParameter("@loc_city", SqlDbType.NVarChar);

loc_cityParam.Value = "";

loc_cityParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(loc_cityParam);

SqlParameter loc_stateParam = new SqlParameter("@loc_state", SqlDbType.NVarChar);

loc_stateParam.Value = "";

loc_stateParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(loc_stateParam);

SqlParameter loc_zipParam = new SqlParameter("@loc_zip", SqlDbType.NVarChar);

loc_zipParam.Value = "";

loc_zipParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(loc_zipParam);

SqlParameter loc_area_codeParam = new SqlParameter("@loc_area_code", SqlDbType.TinyInt);

loc_area_codeParam.Value = "";

loc_area_codeParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(loc_area_codeParam);

SqlParameter loc_addressParam = new SqlParameter("@loc_address", SqlDbType.NVarChar);

loc_addressParam.Value = "";

loc_addressParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(loc_addressParam);



SqlParameter company_guidParam = new SqlParameter("@company_guid", SqlDbType.UniqueIdentifier);

company_guidParam.Value = CGuid;

company_guidParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(company_guidParam);



SqlParameter divisionParam = new SqlParameter("@division", SqlDbType.SmallInt);

divisionParam.Value = "";

divisionParam.Direction = ParameterDirection.Input;

myCommand.Parameters.Add(divisionParam);

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\employers\createneweuser.aspx.cs    Line: 126

Stack Trace:

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2753507
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +102
   System.Byte.Parse(String s, NumberStyles style, NumberFormatInfo info) +22
   System.String.System.IConvertible.ToByte(IFormatProvider provider) +43
   System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +2562420
   System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType) +842

[FormatException: Failed to convert parameter value from a String to a Byte.]
   System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType) +903
   System.Data.SqlClient.SqlParameter.GetCoercedValue() +58
   System.Data.SqlClient.SqlParameter.Validate(Int32 index) +194
   System.Data.SqlClient.SqlCommand.SetUpRPCParameters(_SqlRPC rpc, Int32 startCount, Boolean inSchema, SqlParameterCollection parameters) +153
   System.Data.SqlClient.SqlCommand.BuildRPC(Boolean inSchema, SqlParameterCollection parameters, _SqlRPC& rpc) +107
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1118
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334
   System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +407
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +149
   employers_createneweuser.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Scott\My Documents\Visual Studio 2005\WebSites\jobsite\employers\createneweuser.aspx.cs:126
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +31
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +68
   System.Web.UI.Control.OnLoad(EventArgs e) +88
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3037

 



--------------------------------------------------------------------------------
Avatar of Solar_Flare
Solar_Flare

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?)
Avatar of Scripter25

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_address, @company_guid,@division)
      
ASKER CERTIFIED SOLUTION
Avatar of sandip132
sandip132
Flag of Japan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial