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 LodhaRank #31 · 39.8K reputationPosted Jul 9, 2014, 10:23 PM EDT
Khan Abrar AhmedRank #778 · 3K reputationPosted Jul 9, 2014, 10:23 PM EDT
varsha dodiyaRank #4,270 · 354 reputationPosted Jul 9, 2014, 10:27 PM EDT
Nimit JoshiRank #75 · 24.7K reputationPosted Jul 9, 2014, 10:28 PM EDT
varsha dodiyaRank #4,270 · 354 reputationPosted Jul 9, 2014, 10:29 PM EDT
varsha dodiyaRank #4,270 · 354 reputationPosted Jul 9, 2014, 10:31 PM EDT
Nimit JoshiRank #75 · 24.7K reputationPosted Jul 9, 2014, 10:33 PM EDT
varsha dodiyaRank #4,270 · 354 reputationPosted Jul 9, 2014, 10:40 PM EDT
varsha dodiyaRank #4,270 · 354 reputationPosted Jul 9, 2014, 10:41 PM EDT
Abhishek JaiswalRank #126 · 17.5K reputationPosted Jul 9, 2014, 10:46 PM EDT
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.
Nimit JoshiRank #75 · 24.7K reputationPosted Jul 9, 2014, 10:47 PM EDT
varsha dodiyaRank #4,270 · 354 reputationPosted Jul 9, 2014, 11:05 PM EDT
,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 JoshiRank #75 · 24.7K reputationPosted Jul 9, 2014, 11:18 PM EDT
varsha dodiyaRank #4,270 · 354 reputationPosted Jul 9, 2014, 11:25 PM EDT
Shweta LodhaRank #31 · 39.8K reputationPosted Jul 10, 2014, 12:13 AM EDT
You need to convert into Int becasue you are using numeric(18,0) for P_billno and P_ch_no
Nimit JoshiRank #75 · 24.7K reputationPosted Jul 10, 2014, 7:09 PM EDT
varsha dodiyaRank #4,270 · 354 reputationPosted Jul 10, 2014, 9:43 PM EDT
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 .
Shweta LodhaRank #31 · 39.8K reputationPosted Jul 11, 2014, 12:21 AM EDT
Abhishek JaiswalRank #126 · 17.5K reputationPosted Jul 11, 2014, 9:31 AM EDT
stay tuned, stay updated with C# Corner!
:)
Nimit JoshiRank #75 · 24.7K reputationPosted Jul 13, 2014, 7:25 PM EDT
Palle TechnologiesRank #6,639 · 260 reputationPosted Jul 14, 2014, 6:44 AM EDT
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 ..