when i insert data it throws exception "erroe converting datatype nvarchar to numeric" plz help me in fixing this.
private void btnSave2_Click(object sender, EventArgs e)
{
{
cmd = new SqlCommand("insert into PRO_BILL (S_name,P_billno,P_ch_no,P_pur_date,P_btotal,P_tovat,P_dis,P_gt,P_paid) values (@S_name,@P_billno,@P_ch_no,@P_pur_date,@P_btotal,@P_tovat,@P_dis,@P_gt,'n')", conn);
conn.Open();cmd.Parameters.AddWithValue("@S_name", tbSupname.Text);
cmd.Parameters.AddWithValue("@P_billno", tbBILLNO.Text);
cmd.Parameters.AddWithValue("@P_ch_no", tbCHLNno.Text);
cmd.Parameters.AddWithValue("@P_pur_date", Convert.ToDateTime(dateTimePicker1.Text));
cmd.Parameters.AddWithValue("@P_btotal", tbtot1.Text);
cmd.Parameters.AddWithValue("@P_tovat", tbVAT.Text);
cmd.Parameters.AddWithValue("@P_dis", tbDisTOT.Text);
cmd.Parameters.AddWithValue("@P_gt", tbGT.Text);
cmd.ExecuteNonQuery();
conn.Close();
}

Shweta LodhaPosted Jul 10, 2014, 2:23 AM
Palle TechnologiesPosted Jul 14, 2014, 10:44 AM
cmd = new SqlCommand("insert into PRO_BILL (S_name,P_billno,P_ch_no,P_pur_date,P_btotal,P_tovat,P_dis,P_gt,P_paid) values (@S_name,@P_billno,@P_ch_no,@P_pur_date,@P_btotal,@P_tovat,@P_dis,@P_gt,'n')", conn);
Conn.Open();
SqlParameter P1=new SqlParameter("@S_name",SqlDbType.Varchar,40);
SqlParameter P2=new SqlParameter("@P_billno",SqlDbType.Int);
P2.Value=Convert.ToInte32(tbBILLNO.Text);
...so on...
cmd.Parameter.Add(P1);
Cmd.parameters.Add(P2);
..so on ..
Nimit JoshiPosted Jul 13, 2014, 11:25 PM
Abhishek JaiswalPosted Jul 11, 2014, 1:31 PM
stay tuned, stay updated with C# Corner!
:)
Shweta LodhaPosted Jul 11, 2014, 4:21 AM
varsha dodiyaPosted Jul 11, 2014, 1:43 AM
thank you everyone for your time and support . I am new to c sharp corner but it really helped me from first day of joining it. thanks again .
Nimit JoshiPosted Jul 10, 2014, 11:09 PM
Shweta LodhaPosted Jul 10, 2014, 4:13 AM
You need to convert into Int becasue you are using numeric(18,0) for P_billno and P_ch_no
varsha dodiyaPosted Jul 10, 2014, 3:25 AM
Nimit JoshiPosted Jul 10, 2014, 3:18 AM
varsha dodiyaPosted Jul 10, 2014, 3:05 AM
,P_billno=(numeric(18,0)
,P_ch_no=(numeric(18,0)
,P_pur_date=date
,P_btotal=decimal(18,2),
P_tovat==decimal(18,2),
P_dis=decimal(18,2),
P_gt=decimal(18,2)
P_paid=varchar(5)
Nimit JoshiPosted Jul 10, 2014, 2:47 AM
Abhishek JaiswalPosted Jul 10, 2014, 2:46 AM
Don't use INT or Decimal data-type for @P_btotal,@P_tovat,@P_dis and for other. Always use VARCHAR and fix the size of the VARCHAR(15), as per your need and make sure that you are storing digits only to database.
That's the best way to get rid of these kinda errors.
varsha dodiyaPosted Jul 10, 2014, 2:41 AM
varsha dodiyaPosted Jul 10, 2014, 2:40 AM
Nimit JoshiPosted Jul 10, 2014, 2:33 AM
varsha dodiyaPosted Jul 10, 2014, 2:31 AM
varsha dodiyaPosted Jul 10, 2014, 2:29 AM
Nimit JoshiPosted Jul 10, 2014, 2:28 AM
varsha dodiyaPosted Jul 10, 2014, 2:27 AM
Khan Abrar AhmedPosted Jul 10, 2014, 2:23 AM