Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi friends i am developing inventory software in C# WindowsApplication VS2010 .NET 4.0

i want to insert multiple rows values like shopping item for billing, when i update price in master data of all the item display in gridview with particular amount column will be editable to change the price

here 1st i use select query using retrieve DB data, then that view grid i need particular column will be editable for changes the value and the enter value in that column i click update button all modified data in grid want to update in the database directly



many of the codes are given in readonly="true" code but i try below code get an error


try
            {
                SqlConnection cons = new SqlConnection(constr);
                cons.Open();
                SqlCommand cmd = new SqlCommand("update emp table set empid=" + dataGridView1.ColumnCount + ",empname=" + dataGridView1.ColumnCount + ",empadd=" + dataGridView1.ColumnCount + "");
                SqlDataAdapter sda=new SqlDataAdapter(cmd);
              DataSet ds=new DataSet();
                sda.Fill(ds);
                dataGridView1.DataSource=ds.Tables[0];
                cons.Close();


            }
            catch(Exception)
            {
                
                }


above code is getting an exception argument like error

mainly i use multiple row insert and need price column rows change at editable view product column will not editable how to use grid retrieval and update data easily in c# windowsapplication
Posted
Comments
Robert Welliever 31-Oct-14 1:56am    
What is the thrown exception? Aside from that, you should get in the practice of using the SqlParameter object to defend against Sql injection. Also you're connection is open unnecessarily long. You should open it right before the call to Fill() and close it right after the call to Fill(), or even better yet, do it with a "Using" statement for cleanliness and disposal insurance (on all your db crap i.e. connection, adapter, command object, etc.)
Soundararajan O M 1-Nov-14 4:22am    
hello robert i get confused in gridview C# windows
what i am doing is form1 load display grid database table then i insert and update details in run time of that grid

Example i have pid,prestack,estack,eprice, total,
i need to insert values estack and eprice in editable views in column of grid remain all column will readonly method

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