Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
C#
string query = string.Format("update Product set BalanceOnStock='{0}' where ProHead='{1}'", value.ToString(), ddlItem);

It's still not working please assist me for the same i am sending you the whole coding of the same page...

C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class DailyComsumption : System.Web.UI.Page
{
    SqlConnection cn;
    SqlCommand cm;
    //SqlConnection conn = null;
    //Sqlmmand cmd = new SqlCommand(conn);
    int abc, dal, insert, showdata, baldata,updatebal,updateitem;
    int item;

    protected void Page_Load(object sender, EventArgs e)
    {
        string cs = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=true;User Instance=true";
        cn = new SqlConnection(cs);
        cn.Open();
    }
   
   
    protected void BtPrint_Click(object sender, EventArgs e)
    {
        Response.Redirect("Report.aspx");
    }

    protected void TxtWorkSelection_TextChanged(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        
//string ddlItem = "";
//if (DDLItem.SelectedItem != null)
//{
//   // ddlItem = (Cast to whatever type it is) DDLItem.SelectedItem.Text;
//}
//if (ddlItem != "")
//{
    //try
    //{
    //    conn = new SqlConnection(connectionString);
    //    cmd = new SqlCommand(conn);
    //    cmd.CommandType = CommandType.Text;
    //    foreach (ListItem LBox4Item in ListBox4.Items)
    //    {
    //        ListBox5.Items.Add(LBox4Item);
    //        int value = LBox4Item.ToString();
    //        // In the code you originally posted, you're adding everything in Listbox5 everytime 
    //        // you add something to Listbox5. I'm almost positive this isn't what you wanted to to.
    //        // So, just add the item that was recently added.
    //        string query = string.Format("update Product set BalanceOnStock='{0}' where ProHead='{1}'", value.ToString(), ddlItem);
    //        cmd.CommandText = query;
//            cmd.ExecuteNonQuery();
//        }
//    }
//    catch(Exception ex)
//    {
//        // determine your exception here
//    }
//    finally
//    {
//        if (conn != null)
//        {
//            conn.Close();
//        }
//    } 
//}
        foreach (ListItem LBox4Item in ListBox4.Items)
        {
            ListBox5.Items.Add(LBox4Item);
            int value = Convert.ToInt32( LBox4Item.ToString());
            //updateitem = Convert.ToInt32(LBox5Item.ToString());
            //string q = "update Product set BalanceOnStock='{0}' where ProHead='{1}'", value.oString(), DDLItem;
            //"update Product set BalanceOnStock='" + updateitem.ToString() + "' where ProHead='" + DDLItem.SelectedItem.Text + "'";
            string query = string.Format("update Product set BalanceOnStock='{0}' where ProHead='{1}'", value.ToString(), DDLItem);
            cm = new SqlCommand(query, cn);
            cm.ExecuteNonQuery();
        }                                                            
    }

    protected void  DDLItem_SelectedIndexChanged(object sender, EventArgs e)
        {
        string q = "select QuantityforAssembly, BalanceOnStock from Product where ProHead ='" + DDLItem.SelectedItem.Text + "'";
        cm = new SqlCommand(q, cn);
        SqlDataReader r = cm.ExecuteReader();
        while (r.Read())
        {

            ListBox1.Items.Add(r.GetString(0));
            ListBox2.Items.Add(r[1].ToString());

        }        
        foreach (ListItem LBoxItem in ListBox1.Items)
        {
            abc = Convert.ToInt32(LBoxItem.ToString());
            insert = Convert.ToInt32(TxtWorkSelection.Text);
            dal = Convert.ToInt32(abc * insert);
            ListBox3.Items.Add(dal.ToString());
        }

             
            foreach (ListItem LBox3Item in ListBox3.Items)
            {
                foreach (ListItem LBox2Item in ListBox2.Items)
                {

                    baldata = Convert.ToInt32(LBox2Item.ToString());
                    showdata = Convert.ToInt32(LBox3Item.ToString());
                    updatebal = baldata - showdata;
                }
                ListBox4.Items.Add(updatebal.ToString());
            }                           
        }

        

    protected void BtGenReport_Click(object sender, EventArgs e)
    {        
     //foreach (ListItem LBox4Item in ListBox4.Items)
     //   {
     //       item = Convert.ToInt32(LBox4Item.ToString());
     //       ListBox5.Items.Add(item.ToString());            
     //   }
    


    }
    protected void ListBox4_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void BtClear_Click(object sender, EventArgs e)
    {
        //foreach (ListItem LBoxDelItem in ListBox1.Items)
        //{
        //    ListBox1.Items.Remove(LBoxDelItem.ToString());
        //}
    }
}


Please go to step wise step and give me the solution if possible

The last item value was updated and add to the database each row for example 4910,4910,4910,4910,4910,4910,4910,4910,4910,4910,4910 till statement of for each get not get false.
Posted
Updated 12-Mar-12 5:11am
v3
Comments
Herman<T>.Instance 12-Mar-12 11:16am    
do you get any exception?
R. Giskard Reventlov 12-Mar-12 11:53am    
Try to only give us the code that is causing the problem together with th exception. Have you tried stepping through the code?
Ganesan Senthilvel 12-Mar-12 12:19pm    
Put a break point in foreach loop of SQL update and trace the value on each iteration.
nevin pillai 12-Mar-12 13:37pm    
hi man i need a help in vb to make a control pad program for my wheeled robot...
my program is like this to control my agriculture robot. i dont have any idea in vb if u can make me a gui of the below type pls help me. this one was made by me with help of some reference....

http://www.4shared.com/rar/v7CA_VMT/New_folder.html[^]
[no name] 12-Mar-12 22:11pm    
You are kidding right? Hijacking someone else's question to ask for help on some thing that is not even remotely related is so not cool.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900