How to delete table data in sql by a gui form...with a scnerio

Ignitesoft Pvt. Ltd. is a leading producer of hardware and software products. The details of all the products are maintained in a centralized database system. As a part of the development team, Nikhil is assigned a task to develop a windows based application in which the details of a product on the basis of a product Id is being deleted from the Products table. However, before implementing a delete operation, the details of the product should be displayed on the screen. He has written the following code to accomplish this task. string productCode; productCode = textBox1.Text; string connectionString = "Data Source=JBB-690AB60E108;Initial Catalog=datamaster;Integrated Security = True;MultipleActiveResultSets=True"; SqlConnection cn = new SqlConnection(); cn.ConnectionString = connectionString; cn.Open(); SqlCommand cmd = cn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from newclient where ProductId=@pCode"; cmd.Parameters.Add(new SqlParameter("@pCode", productCode)); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { textBox2.Text = Convert.ToString((dr[1])); textBox3.Text = Convert.ToString((dr[2])); } SqlCommand cmd1 = cn.CreateCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "delete from Products where productId=@pCode"; cmd1.Parameters.Add(new SqlParameter("@pCode", productCode)); SqlDataReader dr1 = cmd1.ExecuteReader(); cn.Close();
Ebook Download
View all
Learn
View all