Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SQL-Server
hi,
In my sql server database table i have a column of type float and it allow null values.
But when from my web form user left that column empty then get error message:
 
System.FormatException was unhandled by user code
Message="Input string was not in a correct format."
 
what to do handle this .
thanks
Posted 21-Dec-12 20:21pm
Comments
choudhary.sumit at 22-Dec-12 2:26am
   
post your code here.
ruby kaur at 27-Dec-12 6:35am
   
This is code from .cs file code

Collapse | Copy Code
protected void btnAdd_Click(object sender, EventArgs e)
{

if (objLotCreation.Insert(ddlDepot.SelectedValue, txtlotcode.Text.Trim(), txtDepo_stackno.Text.Trim(), txtSPECIES_Ename.Text.Trim(),
txtSPECIES_Uname.Text.Trim(), txtSPECIES_Kname.Text.Trim(), txtGrade.Text.Trim(), Convert.ToInt32(txtNo_of_pieces.Text),
txtLength_class.Text.Trim(), txtlblGirth_class.Text.Trim(), Convert.ToDouble(txtCubic_meter.Text), Convert.ToDouble(txtUpset_price.Text),
Convert.ToDouble(txtSale_Price.Text), Convert.ToInt32(Session["OfficeID"].ToString())))
{
lblStatus.Text = Resources.Language.Common_Record_Add;
}
BindGrid(Session["Language"].ToString());
clearfields();
}

This is business logic code
Collapse | Copy Code
public bool Insert(string Depot_Code, string Lot_Code, string Depo_stackno, string SPECIES_Ename, string SPECIES_Uname, string SPECIES_Kname, string Grade,
int No_of_pieces, string Length_class, string Girth_class, double Cubic_meter,double Upset_price,double Sale_Price,int DIV_ID)
{
bool res = false;
System.Collections.ArrayList sel = new System.Collections.ArrayList();

sel.Add("SP_m_LotCreation_Insert");
ArrayList lstParam = new System.Collections.ArrayList();

SqlParameter param;

param = new SqlParameter();
param.ParameterName = "@Depot_Code";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Depot_Code;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@Lot_Code";
param.SqlDbType = SqlDbType.NVarChar;
param.Value = Lot_Code;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@Depo_stackno";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Depo_stackno;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@SPECIES_Ename";
param.SqlDbType = SqlDbType.VarChar;
param.Value = SPECIES_Ename;
lstParam.Add(param);

param = new SqlParameter();
param.ParameterName = "@SPECIES_Uname";
param.SqlDbType = SqlDbType.VarChar;
param.Value = SPECIES_Uname;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@SPECIES_Kname";
param.SqlDbType = SqlDbType.VarChar;
param.Value = SPECIES_Kname;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@Grade";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Grade;
lstParam.Add(param);

param = new SqlParameter();
param.ParameterName = "@No_of_pieces";
param.SqlDbType = SqlDbType.Int;
param.Value = No_of_pieces;
lstParam.Add(param);


param = new SqlParameter();
param.ParameterName = "@Length_class";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Depo_stackno;
lstParam.Add(param);


param = new SqlParameter();
param.ParameterName = "@Girth_class";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Girth_class;
lstParam.Add(param);

param = new SqlParameter();
param.ParameterName = "@Cubic_meter";
param.SqlDbType = SqlDbType.Float;
param.Value = Cubic_meter;
lstParam.Add(param);

param = new SqlParameter();
param.ParameterName = "@Upset_price";
param.SqlD
ruby kaur at 27-Dec-12 6:36am
   
This is code from .cs file code

Collapse | Copy Code
protected void btnAdd_Click(object sender, EventArgs e)
{

if (objLotCreation.Insert(ddlDepot.SelectedValue, txtlotcode.Text.Trim(), txtDepo_stackno.Text.Trim(), txtSPECIES_Ename.Text.Trim(),
txtSPECIES_Uname.Text.Trim(), txtSPECIES_Kname.Text.Trim(), txtGrade.Text.Trim(), Convert.ToInt32(txtNo_of_pieces.Text),
txtLength_class.Text.Trim(), txtlblGirth_class.Text.Trim(), Convert.ToDouble(txtCubic_meter.Text), Convert.ToDouble(txtUpset_price.Text),
Convert.ToDouble(txtSale_Price.Text), Convert.ToInt32(Session["OfficeID"].ToString())))
{
lblStatus.Text = Resources.Language.Common_Record_Add;
}
BindGrid(Session["Language"].ToString());
clearfields();
}

This is business logic code
Collapse | Copy Code
public bool Insert(string Depot_Code, string Lot_Code, string Depo_stackno, string SPECIES_Ename, string SPECIES_Uname, string SPECIES_Kname, string Grade,
int No_of_pieces, string Length_class, string Girth_class, double Cubic_meter,double Upset_price,double Sale_Price,int DIV_ID)
{
bool res = false;
System.Collections.ArrayList sel = new System.Collections.ArrayList();

sel.Add("SP_m_LotCreation_Insert");
ArrayList lstParam = new System.Collections.ArrayList();

SqlParameter param;

param = new SqlParameter();
param.ParameterName = "@Depot_Code";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Depot_Code;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@Lot_Code";
param.SqlDbType = SqlDbType.NVarChar;
param.Value = Lot_Code;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@Depo_stackno";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Depo_stackno;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@SPECIES_Ename";
param.SqlDbType = SqlDbType.VarChar;
param.Value = SPECIES_Ename;
lstParam.Add(param);

param = new SqlParameter();
param.ParameterName = "@SPECIES_Uname";
param.SqlDbType = SqlDbType.VarChar;
param.Value = SPECIES_Uname;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@SPECIES_Kname";
param.SqlDbType = SqlDbType.VarChar;
param.Value = SPECIES_Kname;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@Grade";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Grade;
lstParam.Add(param);

param = new SqlParameter();
param.ParameterName = "@No_of_pieces";
param.SqlDbType = SqlDbType.Int;
param.Value = No_of_pieces;
lstParam.Add(param);


param = new SqlParameter();
param.ParameterName = "@Length_class";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Depo_stackno;
lstParam.Add(param);


param = new SqlParameter();
param.ParameterName = "@Girth_class";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Girth_class;
lstParam.Add(param);

param = new SqlParameter();
param.ParameterName = "@Cubic_meter";
param.SqlDbType = SqlDbType.Float;
param.Value = Cubic_meter;
lstParam.Add(param);

param = new SqlParameter();
param.ParameterName = "@Upset_price";
param.SqlD
AshishChaudha at 22-Dec-12 6:06am
   
have you tried something??
Krunal Rohit at 22-Dec-12 11:02am
   
code ????????
ruby kaur at 27-Dec-12 6:36am
   
This is code from .cs file code

Collapse | Copy Code
protected void btnAdd_Click(object sender, EventArgs e)
{

if (objLotCreation.Insert(ddlDepot.SelectedValue, txtlotcode.Text.Trim(), txtDepo_stackno.Text.Trim(), txtSPECIES_Ename.Text.Trim(),
txtSPECIES_Uname.Text.Trim(), txtSPECIES_Kname.Text.Trim(), txtGrade.Text.Trim(), Convert.ToInt32(txtNo_of_pieces.Text),
txtLength_class.Text.Trim(), txtlblGirth_class.Text.Trim(), Convert.ToDouble(txtCubic_meter.Text), Convert.ToDouble(txtUpset_price.Text),
Convert.ToDouble(txtSale_Price.Text), Convert.ToInt32(Session["OfficeID"].ToString())))
{
lblStatus.Text = Resources.Language.Common_Record_Add;
}
BindGrid(Session["Language"].ToString());
clearfields();
}

This is business logic code
Collapse | Copy Code
public bool Insert(string Depot_Code, string Lot_Code, string Depo_stackno, string SPECIES_Ename, string SPECIES_Uname, string SPECIES_Kname, string Grade,
int No_of_pieces, string Length_class, string Girth_class, double Cubic_meter,double Upset_price,double Sale_Price,int DIV_ID)
{
bool res = false;
System.Collections.ArrayList sel = new System.Collections.ArrayList();

sel.Add("SP_m_LotCreation_Insert");
ArrayList lstParam = new System.Collections.ArrayList();

SqlParameter param;

param = new SqlParameter();
param.ParameterName = "@Depot_Code";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Depot_Code;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@Lot_Code";
param.SqlDbType = SqlDbType.NVarChar;
param.Value = Lot_Code;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@Depo_stackno";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Depo_stackno;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@SPECIES_Ename";
param.SqlDbType = SqlDbType.VarChar;
param.Value = SPECIES_Ename;
lstParam.Add(param);

param = new SqlParameter();
param.ParameterName = "@SPECIES_Uname";
param.SqlDbType = SqlDbType.VarChar;
param.Value = SPECIES_Uname;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@SPECIES_Kname";
param.SqlDbType = SqlDbType.VarChar;
param.Value = SPECIES_Kname;
lstParam.Add(param);

 
param = new SqlParameter();
param.ParameterName = "@Grade";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Grade;
lstParam.Add(param);

param = new SqlParameter();
param.ParameterName = "@No_of_pieces";
param.SqlDbType = SqlDbType.Int;
param.Value = No_of_pieces;
lstParam.Add(param);


param = new SqlParameter();
param.ParameterName = "@Length_class";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Depo_stackno;
lstParam.Add(param);


param = new SqlParameter();
param.ParameterName = "@Girth_class";
param.SqlDbType = SqlDbType.VarChar;
param.Value = Girth_class;
lstParam.Add(param);

param = new SqlParameter();
param.ParameterName = "@Cubic_meter";
param.SqlDbType = SqlDbType.Float;
param.Value = Cubic_meter;
lstParam.Add(param);

param = new SqlParameter();
param.ParameterName = "@Upset_price";
param.SqlD
Surendra0x2 at 22-Dec-12 11:41am
   
May b type casting issue or ur not filing fload value in the textbox.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,
It would better if you submitted your code. ok, as per your explanation, You are sending null value in database. this is not problem of course you can send null value in database but problem is when you are converting your null value in float type then the error occurs. because you can convert null value to float.
 
thank you.
Rashed::Bangladesh.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Refer this:
 
Click Here[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 534
1 Gihan Liyanage 298
2 RyanDev 270
3 Sergey Alexandrovich Kryukov 223
4 Richard Deeming 185
0 Sergey Alexandrovich Kryukov 8,906
1 OriginalGriff 7,771
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 9 Apr 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100