14
Answers

ADO.NET DATAGRIDVIEW UPDATE

Ask a question
Bineesh  VP

Bineesh VP

11y
826
1
Sir, I am doing a Program of ADO.NET SAVE, UPDATE and DELETE

My form's name is frmProduct.

I want your help in the update process.

here is my form;





I did the coding for functioning Save and View.

the data passes from gridView to textBox when I double click in gridView and text of button Save change to "Update".

and I need your help from here.


I am getting error"




here is the code I wrote in the SP class;

public void productEdit(productInfo infoProduct)
        {
            try
            {
                if (sqlCon.State == ConnectionState.Closed)
                {
                    sqlCon.Open();
                }
                SqlCommand sqlCmd = new SqlCommand("productEdit", sqlCon);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.Add("@productId", SqlDbType.Decimal).Value = infoProduct.productId;
                sqlCmd.Parameters.Add("@productName", SqlDbType.NVarChar).Value = infoProduct.productName;
                sqlCmd.Parameters.Add("@purchaseRate", SqlDbType.Decimal).Value = infoProduct.purchaseRate;
                sqlCmd.Parameters.Add("@salesRate", SqlDbType.Decimal).Value = infoProduct.salesRate;
                int incount = sqlCmd.ExecuteNonQuery();
                if (incount > 0)
                {
                    MessageBox.Show("Update Successfully");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PrSP04" + ex.Message);
            }
            finally
            {
                sqlCon.Close();
            }

        }


here the code I wrote in the button_click event

   private void btnSave_Click(object sender, EventArgs e)
        {
            productInfo infoproduct=new productInfo();
            productSP SpProduct=new productSP();
            infoproduct.productId = decProduct;
            infoproduct.productName = txtProductName.Text.ToString();
            infoproduct.purchaseRate = decimal.Parse(txtpurchaseRate.Text);
            infoproduct.salesRate = decimal.Parse(txtsalesReport.Text);
            if (btnSave.Text == "Save")
            {
             SpProduct.productAdd(infoproduct);
         
            }
            else
            {
             SpProduct.productEdit(infoproduct);
            
            }
            ProductgridFill();
            clearAll();
 
        }


please help me in this error

Answers (14)