Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
|
Forums » .NET » ASP.NET »
Suggstion needed in code
Posted Date: 03 Jul 2009 Posted By: gopal.net Member Level: Gold Points: 1
Responses:
3
|
hi to all,
Iam adding textbox values and Gridview footer Textbox values in to database.
This is my code
st = ""; st = st + tb_vendname.Text + "','"; st = st + tb_stno.Text + "','"; st = st + tb_city.Text + "',"; st = st + tb_pin.Text + ",'"; st = st + tb_tin.Text + "','"; st = st + tb_tel.Text + "','"; st = st + DL_vencode.Text + "','"; st = st + tb_mail.Text + "','"; st = st + tb_cntctpersn.Text + "','"; st = st + tb_ordrno.Text + "','"; st = st + tb_ordrdate.Text + "','"; st = st + tb_kstno.Text + "','"; st = st + tb_cstno.Text + "','"; st = st + tb_tin1.Text + "','"; st = st + tb_pureqno.Text + "','"; st = st + tb_purreqdate.Text + "','"; st = st + tb_purreqby.Text + "',"; st = st + tb_quoteno.Text + ","; st = st + tb_offerno.Text + ",'"; st = st + tb_offdate.Text + "',"; st = st + tb_proinvno.Text + ",'"; st = st + TextBox1.Text + "'"; String Stri = "Insert into Purordr (purordr_vendor_name,purordr_stno,purordr_city,purordr_pin,purordr_tin,purordr_telephone,purordr_vendorcode,purordr_mail,purordr_cntct_person,purordr_pur_ordno,purordr_pur_orddate,purordr_kstno,purordr_cstno,purordr_tin1,purordr_pureq_no,purordr_pureq_date,purordr_reqst_by,purordr_quote_no,purordr_offer_no,purordr_offer_date,purordr_ProInv_no,sno,Part_Drawing,Description,Quantity,Unitprice,Amount,deldate) values(" + st + ",@SerialNo,@Part_Drawing,@Description,@Quantity,@Unitprice,@Amount,@deldate)"; SqlCommand cmd = new SqlCommand(Stri, con); //cmd.Parameters.Add("@SerialNo", SqlDbType.Int, 4).Value = ((TextBox)GridView1.FooterRow.FindControl("footertxtPart_Drawing")).Text; cmd.Parameters.Add("@Part_Drawing", SqlDbType.VarChar, 15).Value = ((TextBox)GridView1.FooterRow.FindControl("footertxtPart_Drawing")).Text; cmd.Parameters.Add("@Description", SqlDbType.VarChar, 20).Value = ((TextBox)GridView1.FooterRow.FindControl("footertxtDescription")).Text; cmd.Parameters.Add("@Quantity", SqlDbType.Int, 4).Value = ((TextBox)GridView1.FooterRow.FindControl("footertxtQuantity")).Text; cmd.Parameters.Add("@Unitprice", SqlDbType.Float, 8).Value = convert.ToInt32(((TextBox)GridView1.FooterRow.FindControl("footertxtUnitprice")).Text); cmd.Parameters.Add("@Amount", SqlDbType.Float, 8).Value = ((TextBox)GridView1.FooterRow.FindControl("footertxtAmount")).Text; cmd.Parameters.Add("@deldate", SqlDbType.SmallDateTime, 4).Value = ((TextBox)GridView1.FooterRow.FindControl("footertxtdeldate")).Text; con.Open(); cmd.ExecuteNonQuery(); con.Close();
The following is Error message
FormatException was unhandled by usercode
ErrorInput stream is not in a correct format showing at QUANTITY.
suggestions required for this code
suggest me to do this.
gopal.net
|
Responses
|
| Author: ABitSmart 03 Jul 2009 | Member Level: Diamond | Rating:  Points: 2 | Try this,
cmd.Parameters.Add("@Quantity", SqlDbType.Int, 4).Value = Convert.ToInt32(((TextBox)GridView1.FooterRow.FindControl("footertxtQuantity")).Text); cmd.Parameters.Add("@Unitprice", SqlDbType.Float, 8).Value = Convert.ToInt64(((TextBox)GridView1.FooterRow.FindControl("footertxtUnitprice")).Text); cmd.Parameters.Add("@Amount", SqlDbType.Float, 8).Value = Convert.ToInt64(((TextBox)GridView1.FooterRow.FindControl("footertxtAmount")).Text);
Kind regards, ABitSmart DNS Web-master, DNS MVM My blog Thoughts.exe
| | Author: Varun Bansal 03 Jul 2009 | Member Level: Gold | Rating:  Points: 2 | plz check your datatype of quantity field in database
Regards Varun bansal Do ot forget to Rate the post..... Click here for visiting in my blogs
| | Author: Devendra 04 Jul 2009 | Member Level: Gold | Rating:  Points: 2 | Dear,
You Did not Convert The value of Quantity Parameter type of quantity is int while you are assigning value that is string
You can change this line like
cmd.Parameters.Add("@Quantity", SqlDbType.Int, 4).Value = (int)(((TextBox)GridView1.FooterRow.FindControl("footertxtQuantity")).Text);
Just I did the type casting from string to Int U can use Convert.toint as well to do type casting
Do ot forget to Rate the post.....
|
| Post Reply |
|
|
|
 | | This thread is locked for new responses. Please post your comments and questions as a separate thread. If required, refer to the URL of this page in your new post. |
|
|
|
|