Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 .NET4 ASP.NET4.0
i have one form with few textboxes through which i add data into the grid using datatable and now i want to add data of grid to the table (Tbl_Invoice) with columns Invoice_Id(PK and identity specification true),Product_Name(nvarchar(50),Amount(numeric(10,2)),Product_Quantity(int),Product_Price(numeric(10,2)).
 
coding is
 
protected void Button3_Click(object sender, EventArgs e)
    {  foreach (GridViewRow g1 in grd.Rows)  //i have  first 2 columns in which i took button field EDIT and REMOVE ,so how will start my loop
        {     SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["test"].ConnectionString);
            SqlCommand com;
            com = new SqlCommand("insert into Tbl_Invoice(Product_Name,Amount,Product_Quantity,Product_Price) values ('" + g1.Cells[2].Text + "'," + g1.Cells[3].Text + "," + g1.Cells[4].Text + "," + g1.Cells[5].Text + ")", con);
            con.Open();
            com.ExecuteNonQuery();
            con.Close();
            Label1.Text = "Records inserted successfully";
        }   }
public partial class invoice : System.Web.UI.Page
{
    DataTable dt = new DataTable();
    DataRow dr;
    public SqlDataReader reader;
    Query.product objprdt = new product(System.Configuration.ConfigurationManager.ConnectionStrings["test"].ToString());
    Query.customer objcus = new customer(System.Configuration.ConfigurationManager.ConnectionStrings["test"].ToString());
 
    Query.cal objcal = new cal(System.Configuration.ConfigurationManager.ConnectionStrings["test"].ToString());
    DataTable dt1 = new DataTable();
 

 
  protected void Button2_Click(object sender, EventArgs e)
    {  //on click button values of text are added into grid using datatable...i have 2 first column in which i took button field EDIT and Remove
            dt.Columns.Add("Product Name");
 
            dt.Columns.Add("Amount");
            dt.Columns.Add("Qty");
            dt.Columns.Add("Product Price");
 
            for (int intCnt = 0; intCnt < grd.Rows.Count; intCnt++)
            {
                if (grd.Rows[intCnt].RowType == DataControlRowType.DataRow)
                {
                    dr = dt.NewRow();
                    dr["Product Name"] = grd.Rows[intCnt].Cells[2].Text;
                    dr["Amount"] = grd.Rows[intCnt].Cells[3].Text;
                    dr["Qty"] = grd.Rows[intCnt].Cells[4].Text;
                    dr["Product Price"] = grd.Rows[intCnt].Cells[5].Text;
                    dt.Rows.Add(dr);
                }
            }
            dr = dt.NewRow();
            dr["Product Name"] = TextBox6.Text;
            dr["Amount"] = TextBox5.Text;
            dr["Qty"] = TextBox4.Text;
            dr["Product Price"] = TextBox3.Text;
            dt.Rows.Add(dr);
            grd.DataSource = dt;
            grd.DataBind();
     
    }
 

i am getting an error "Invalid column name 'Product_Price' "on com.executenonquery
pls help
regards
Posted 6-Feb-13 23:01pm
Edited 6-Feb-13 23:15pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

it was my stupidity
 
i wrote wrong column name
thanks everyone for viewing it and appologize for ur time
regards
  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 325
1 DamithSL 265
2 CPallini 235
3 Sergey Alexandrovich Kryukov 229
4 Maciej Los 190
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 7 Feb 2013
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