how to overcome this error invalid column name invoiceid?

Posted by Sudheep.grandhe under C# on 12/13/2011 | Points: 10 | Views : 2942 | Status : [Member] | Replies : 3
Hi,

how to overcome this errors.please help me.Invalid column name 'invoiceid'.if any mistakes in my code please correct it.

DBConnection db = new DBConnection();
SqlConnection con = db.opencon();
SqlCommand cmd = new SqlCommand("insert into tbl_report2 (compname,compaddress,orderno,ondate,invoicedate,amountstatus,netamount,netvat,tamount)values(@compname,@compaddress,@orderno,@ondate,@invoicedate,@amountstatus,@netamount,@netvat,@tamount)", con);
SqlCommand cmd2 = new SqlCommand("insert into tbl_report1 (particulars,quantity,perprice,amount,orderno,compname,invoicedate,ondate,invoiceid) select particulars,quantity,perprice,amount,orderno,compname,invoicedate,ondate,invoiceid from tbl_temp", con);
cmd.Parameters.AddWithValue("@compname", cmb_companyname.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@compaddress", txt_customeraddress.Text);
cmd.Parameters.AddWithValue("@invoiceno", txt_invoiceno.Text);
cmd.Parameters.AddWithValue("@orderno", txt_orderno.Text);
if (txt_invoicedate.Text != null && txt_invoicedate.Text.Trim() != "")
{
cmd.Parameters.AddWithValue("@invoicedate", txt_invoicedate.Text);
}
else
{
cmd.Parameters.AddWithValue("@invoicedate", DBNull.Value);
}
if (txt_ondate.Text != null && txt_ondate.Text != "")
{
cmd.Parameters.AddWithValue("@ondate", txt_ondate.Text);
}
else
{
cmd.Parameters.AddWithValue("@ondate", DBNull.Value);
}


cmd.Parameters.AddWithValue("@amountstatus", rb_paid.Checked);
cmd.Parameters.AddWithValue("@amount", rb_unpaid.Checked);
cmd.Parameters.AddWithValue("@netamount", txt_netamount.Text);
cmd.Parameters.AddWithValue("@netvat", txt_vat.Text);
cmd.Parameters.AddWithValue("@tamount", txt_totalamount.Text);
cmd.Parameters.AddWithValue("@invoiceid",txt_invoiceno .Text );
SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
SqlDataAdapter da = new SqlDataAdapter(cmd);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.ExecuteNonQuery();
cmd2.ExecuteNonQuery();//error comes here as :Invalid column name 'invoiceid'.
con.Close();

}

Best,
Sudheep.



Responses

Posted by: Hmanjarawala on: 12/13/2011 [Member] Bronze | Points: 25

Up
0
Down
plz check your query you've written for SqlCommand cmd.
in query there are no parameters named @invoiceid and @invoiceno.

plz verify it

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 12/13/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

it shows the error in SqlCommand cmd2 = new SqlCommand("insert into tbl_report1 (particulars,quantity,perprice,amount,orderno,compname,invoicedate,ondate,invoiceid) select particulars,quantity,perprice,amount,orderno,compname,invoicedate,ondate,invoiceid from tbl_temp", con);

in this invoiceid is there it shows the error as invalid columnname invoiceid

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 12/13/2011 [Member] Bronze | Points: 25

Up
0
Down
Ok,
then plz check any of these two tables may not contain column named "invoiceid" or spelling mistake may be there

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response