datatable filter expression......
-
Hi to all, I have in a datatable select method. I am unable to find what is going wrong. Please give some guidance. I am trying to do like this:
public void get\_data() { try { pro\_id = Request.QueryString\["pr\_id"\]; quanti = Convert.ToInt32(Request.QueryString\["quant"\]); if (pro\_id != null) { SqlConnection con = new SqlConnection("Server=.; Database=eclsc; Trusted\_Connection=yes"); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "select ICEMACHINES.product\_id,ICEMACHINES.sh\_desc,ICEMACHINES.price from ICEMACHINES where ICEMACHINES.product\_id LIKE @product\_id union select GLASSWARE.product\_id,GLASSWARE.sh\_desc,GLASSWARE.price from GLASSWARE where GLASSWARE.product\_id LIKE @product\_id "; cmd.Parameters.Add("@product\_id", SqlDbType.NVarChar, 50).Value = pro\_id; cmd.Connection.Open(); SqlDataReader rdr = cmd.ExecuteReader(); ArrayList arRole1 = new ArrayList(); while (rdr.Read()) { desc = (rdr\["sh\_desc"\]).ToString(); id = (rdr\["product\_id"\]).ToString(); unitprice = Convert.ToSingle((rdr\["price"\])); cost = unitprice \* quanti; } cmd.Connection.Close(); DataRow myrow = dt.NewRow(); myrow\["REF"\] = id; myrow\["Description"\] = desc; myrow\["QTY"\] = quanti; myrow\["Price"\] = unitprice; myrow\["Cost"\] = cost; int dtcount = dt.Rows.Count; if (dtcount > 0) { DataRow\[\] arrMatchingValues = dt.Select("REF=" + id); if (arrMatchingValues.Length > 0) { DataRow drUpdateMe = arrMatchingValues\[0\]; int drUpdateQuant = Convert.ToInt32(drUpdateMe\["QTY"\]); int quan = quanti + drUpdateQuant; drUpdateMe\["QTY"\] = quan; dt.AcceptChanges(); } } else { dt.Rows.Add(myrow); dt.AcceptChanges(); } Session\["data"\] = dt; GridView1.DataSource = dt; GridView1.
-
Hi to all, I have in a datatable select method. I am unable to find what is going wrong. Please give some guidance. I am trying to do like this:
public void get\_data() { try { pro\_id = Request.QueryString\["pr\_id"\]; quanti = Convert.ToInt32(Request.QueryString\["quant"\]); if (pro\_id != null) { SqlConnection con = new SqlConnection("Server=.; Database=eclsc; Trusted\_Connection=yes"); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "select ICEMACHINES.product\_id,ICEMACHINES.sh\_desc,ICEMACHINES.price from ICEMACHINES where ICEMACHINES.product\_id LIKE @product\_id union select GLASSWARE.product\_id,GLASSWARE.sh\_desc,GLASSWARE.price from GLASSWARE where GLASSWARE.product\_id LIKE @product\_id "; cmd.Parameters.Add("@product\_id", SqlDbType.NVarChar, 50).Value = pro\_id; cmd.Connection.Open(); SqlDataReader rdr = cmd.ExecuteReader(); ArrayList arRole1 = new ArrayList(); while (rdr.Read()) { desc = (rdr\["sh\_desc"\]).ToString(); id = (rdr\["product\_id"\]).ToString(); unitprice = Convert.ToSingle((rdr\["price"\])); cost = unitprice \* quanti; } cmd.Connection.Close(); DataRow myrow = dt.NewRow(); myrow\["REF"\] = id; myrow\["Description"\] = desc; myrow\["QTY"\] = quanti; myrow\["Price"\] = unitprice; myrow\["Cost"\] = cost; int dtcount = dt.Rows.Count; if (dtcount > 0) { DataRow\[\] arrMatchingValues = dt.Select("REF=" + id); if (arrMatchingValues.Length > 0) { DataRow drUpdateMe = arrMatchingValues\[0\]; int drUpdateQuant = Convert.ToInt32(drUpdateMe\["QTY"\]); int quan = quanti + drUpdateQuant; drUpdateMe\["QTY"\] = quan; dt.AcceptChanges(); } } else { dt.Rows.Add(myrow); dt.AcceptChanges(); } Session\["data"\] = dt; GridView1.DataSource = dt; GridView1.
-
Hi to all, I have in a datatable select method. I am unable to find what is going wrong. Please give some guidance. I am trying to do like this:
public void get\_data() { try { pro\_id = Request.QueryString\["pr\_id"\]; quanti = Convert.ToInt32(Request.QueryString\["quant"\]); if (pro\_id != null) { SqlConnection con = new SqlConnection("Server=.; Database=eclsc; Trusted\_Connection=yes"); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "select ICEMACHINES.product\_id,ICEMACHINES.sh\_desc,ICEMACHINES.price from ICEMACHINES where ICEMACHINES.product\_id LIKE @product\_id union select GLASSWARE.product\_id,GLASSWARE.sh\_desc,GLASSWARE.price from GLASSWARE where GLASSWARE.product\_id LIKE @product\_id "; cmd.Parameters.Add("@product\_id", SqlDbType.NVarChar, 50).Value = pro\_id; cmd.Connection.Open(); SqlDataReader rdr = cmd.ExecuteReader(); ArrayList arRole1 = new ArrayList(); while (rdr.Read()) { desc = (rdr\["sh\_desc"\]).ToString(); id = (rdr\["product\_id"\]).ToString(); unitprice = Convert.ToSingle((rdr\["price"\])); cost = unitprice \* quanti; } cmd.Connection.Close(); DataRow myrow = dt.NewRow(); myrow\["REF"\] = id; myrow\["Description"\] = desc; myrow\["QTY"\] = quanti; myrow\["Price"\] = unitprice; myrow\["Cost"\] = cost; int dtcount = dt.Rows.Count; if (dtcount > 0) { DataRow\[\] arrMatchingValues = dt.Select("REF=" + id); if (arrMatchingValues.Length > 0) { DataRow drUpdateMe = arrMatchingValues\[0\]; int drUpdateQuant = Convert.ToInt32(drUpdateMe\["QTY"\]); int quan = quanti + drUpdateQuant; drUpdateMe\["QTY"\] = quan; dt.AcceptChanges(); } } else { dt.Rows.Add(myrow); dt.AcceptChanges(); } Session\["data"\] = dt; GridView1.DataSource = dt; GridView1.
hi, Actually what is your task, DataRow myrow = dt.NewRow(); myrow["REF"] = id; myrow["Description"] = desc; myrow["QTY"] = quanti; myrow["Price"] = unitprice; myrow["Cost"] = cost; int dtcount = dt.Rows.Count; if (dtcount > 0) { DataRow[] arrMatchingValues = dt.Select("REF=" + id); in this code your searching for the id which is added to same datatable previously...
-
hi, Actually what is your task, DataRow myrow = dt.NewRow(); myrow["REF"] = id; myrow["Description"] = desc; myrow["QTY"] = quanti; myrow["Price"] = unitprice; myrow["Cost"] = cost; int dtcount = dt.Rows.Count; if (dtcount > 0) { DataRow[] arrMatchingValues = dt.Select("REF=" + id); in this code your searching for the id which is added to same datatable previously...
-
hi, I mean to say that suppose user add a item whose product_id is "CB920". Now user again enters the same item then only the quantity should be updated. This code will only work if there will be atleast one row already in the cart.Then when the next item will come this function will check the datatable for the particular row. If found then it will update the quantity otherwise it will add a new row. This I want to do.
cheers, sneha
-
if your getting any error after debug plz.. write that error.. in this you will get only one row ......
hi, Thanks for your response. Actually it is giving the error in the filter expression term. The error is "There is no column named [CB920]" This is id of the product which user is selecting.
cheers, sneha
-
hi, Thanks for your response. Actually it is giving the error in the filter expression term. The error is "There is no column named [CB920]" This is id of the product which user is selecting.
cheers, sneha
-
in this first you have to create column for dt. ex:dt.column.add[...]; after that write this code. DataRow myrow = dt.NewRow(); myrow["REF"] = id; myrow["Description"] = desc; myrow["QTY"] = quanti; myrow["Price"] = unitprice; myrow["Cost"] = cost;
rajmca.g wrote:
in this first you have to create column for dt. ex:dt.column.add[...];
Hi, But I have five fixed columns(REF,Description,QTY,Price,Cost).And row matching is done as per "REF" column which is already there. And at the 0th position of the datatable the column name is "REF" Please tell me which you are talking about.
cheers, sneha
-
rajmca.g wrote:
in this first you have to create column for dt. ex:dt.column.add[...];
Hi, But I have five fixed columns(REF,Description,QTY,Price,Cost).And row matching is done as per "REF" column which is already there. And at the 0th position of the datatable the column name is "REF" Please tell me which you are talking about.
cheers, sneha
Hi Sneha, Any way you are binding to the data to Gridview. so, you can do updating the data in gridview. then it will works fine. Actually, for data table you can't set datakeys value as we can do for gridview. cehck it out. Regards Ravi