I have a problem about my project
My project :
i need enter a new Row on datatable and database will upraise to Datagridview on Form
I use code to add new row :
DataRow n = tb.NewRow();
n["FoodName"] = "Pepsi";
n["Quantity"] = 1;
tb.Rows.Add(n);
datagridview:
i have a datagridview
FoodName (Column)| Quantity(Column)
| FoodName | Quantity |
| FoodName | Quantity |
| Pepsi | 1 |
| FoodName | Quantity |
| Pepsi | 2 |
as button CocaCola , Button Coffee
Please Help me !!
my e-mail: [email protected]
you can send e-mail for me !! Thankyou Everyone read !!!
Santhosh Kumar JayaramanPosted Jan 9, 2013, 12:42 PM
Duong AnhPosted Jan 9, 2013, 12:38 PM
in Future ! if i have problems with C# . Can you help me ? Please ! :)
Thanks You !!! :)
Santhosh Kumar JayaramanPosted Jan 9, 2013, 12:25 PM
private void btnPepsi_Click(object sender, EventArgs e)
{
bool flag = false;
foreach (DataRow dr in table.Rows)
{
if (dr["Drinks"].ToString() == "Pepsi")
{
dr["Quantity"] = Convert.ToInt32(dr["Quantity"]) + 1;
flag = true;
break;
}
else
{
flag = false;
}
}
if (!flag)
{
DataRow n = table.NewRow();
n["Drinks"] = "Pepsi";
n["Quantity"] = 1;
table.Rows.Add(n);
}
}
private void btnCoca_Click(object sender, EventArgs e)
{
bool flag=false;
foreach (DataRow dr in table.Rows)
{
if (dr["Drinks"].ToString() == "CocoCola")
{
dr["Quantity"] = Convert.ToInt32(dr["Quantity"]) + 1;
flag=true;
break;
}
else
{
flag=false;
}
}
if (!flag)
{
DataRow n = table.NewRow();
n["Drinks"] = "CocoCola";
n["Quantity"] = 1;
table.Rows.Add(n);
}
}
private void btnCoffe_Click(object sender, EventArgs e)
{
bool flag = false;
foreach (DataRow dr in table.Rows)
{
if (dr["Drinks"].ToString() == "Coffee")
{
dr["Quantity"] = Convert.ToInt32(dr["Quantity"]) + 1;
flag = true;
break;
}
else
{
flag = false;
}
}
if (!flag)
{
DataRow n = table.NewRow();
n["Drinks"] = "Coffee";
n["Quantity"] = 1;
table.Rows.Add(n);
}
}
Duong AnhPosted Jan 9, 2013, 12:09 PM
but
Only Quantily of First Rows is increase,
Only first Rows is increase while I click on buttons
3
1
1
1
Or
3
1
1
1
I want
3
3
While I click button Pepsi = 3 times, Cocacola = 3 times and Coffee = 3 times !!!
Santhosh Kumar JayaramanPosted Jan 9, 2013, 11:53 AM
"I believe its working as expected, so please mark the answer as accepted . If not please download my completed project."
Duong AnhPosted Jan 9, 2013, 11:50 AM
I need project which you help me write code for btnCoca and btnCoffee !!
You should check file attach !! :(
Santhosh Kumar JayaramanPosted Jan 9, 2013, 11:44 AM
Duong AnhPosted Jan 9, 2013, 11:41 AM
I need your my project !!
I will grateful IF you help me complete it !! :)
Santhosh Kumar JayaramanPosted Jan 9, 2013, 11:30 AM
Duong AnhPosted Jan 9, 2013, 11:27 AM
Santhosh Kumar JayaramanPosted Jan 9, 2013, 11:23 AM
private void btnCoffe_Click(object sender, EventArgs e)
{
if (table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
if (dr["Drinks"].ToString() == "Coffee")
{
dr["Quantity"] = Convert.ToInt32(dr["Quantity"]) + 1;
break;
}
else
{
DataRow n = table.NewRow();
n["Drinks"] = "Coffee";
n["Quantity"] = 1;
table.Rows.Add(n);
break;
}
}
}
else
{
DataRow n = table.NewRow();
n["Drinks"] = "Coffee";
n["Quantity"] = 1;
table.Rows.Add(n);
}
}
Santhosh Kumar JayaramanPosted Jan 9, 2013, 11:22 AM
private void btnCoca_Click(object sender, EventArgs e)
{
if (table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
if (dr["Drinks"].ToString() == "CocoCola")
{
dr["Quantity"] = Convert.ToInt32(dr["Quantity"]) + 1;
break;
}
else
{
DataRow n = table.NewRow();
n["Drinks"] = "CocoCola";
n["Quantity"] = 1;
table.Rows.Add(n);
break;
}
}
}
else
{
DataRow n = table.NewRow();
n["Drinks"] = "CocoCola";
n["Quantity"] = 1;
table.Rows.Add(n);
}
}
Duong AnhPosted Jan 9, 2013, 11:19 AM
I'm studing it . :D
Santhosh Kumar JayaramanPosted Jan 9, 2013, 11:15 AM
Wherever "pepsi" is there replace it with "Coco Cola".
thats it.. no other changes required;
Duong AnhPosted Jan 9, 2013, 11:13 AM
if i click button Pepsi , Pepsi's Quantiy is increase After I click cocacola is add row
Cocacola 1
cocacola 1
cocacola 1 !! :(
Santhosh Kumar JayaramanPosted Jan 9, 2013, 11:07 AM
private void btnPepsi_Click(object sender, EventArgs e)
{
if (table.Rows.Count > 0)
{
foreach (DataRow dr in table.Rows)
{
if (dr["Drinks"].ToString() == "Pepsi")
{
dr["Quantity"] = Convert.ToInt32(dr["Quantity"]) + 1;
break;
}
else
{
DataRow n = table.NewRow();
n["Drinks"] = "Pepsi";
n["Quantity"] = 1;
table.Rows.Add(n);
break;
}
}
}
else
{
DataRow n = table.NewRow();
n["Drinks"] = "Pepsi";
n["Quantity"] = 1;
table.Rows.Add(n);
}
}
I have attached working project.
Duong AnhPosted Jan 9, 2013, 10:45 AM
this is my ex
Duong AnhPosted Jan 9, 2013, 10:44 AM
chellappan pandiarajanPosted Jan 9, 2013, 9:32 AM
Here i have attached the Sample. I think it will help you.
-Pandian
Dorababu MekaPosted Jan 9, 2013, 9:02 AM
Dorababu MekaPosted Jan 9, 2013, 8:52 AM
Duong AnhPosted Jan 9, 2013, 8:44 AM
p/s: My project isn't need database SQl !!
Dorababu MekaPosted Jan 9, 2013, 8:40 AM