Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Please tell me what is wrong with this

Posted on 2006-11-19
3
857 Views
Last Modified: 2008-01-09
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

 



--------------------------------------------------------------------------------
0
Comment
Question by:Scripter25
3 Comments
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 17976328
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?)
0
 

Author Comment

by:Scripter25
ID: 17976367
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)
      
0
 
LVL 12

Accepted Solution

by:
sandip132 earned 500 total points
ID: 17976688
Here it is.

string CGuid = "";   // a Null String

SqlParameter company_guidParam = new SqlParameter("@company_guid", SqlDbType.UniqueIdentifier);   /// Here it is of type "UniqueIdentifier".

P.S.
If any column of the table is auto increment do not pass any value to your stored proc. and dont specify it in insert statement.



0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question