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

Iftikar HussainPosted Jul 22, 2013, 12:48 AM
Regards,
Iftikar
Bineesh ViswanathPosted Jul 22, 2013, 12:34 AM
public partial class frmProduct : Form
{
decimal decProduct;
public frmProduct()
{
InitializeComponent();
}
Iftikar HussainPosted Jul 22, 2013, 12:05 AM
Regards,
Iftikar
Bineesh ViswanathPosted Jul 21, 2013, 11:58 PM
If you have any other method to update this form, please send me immediately
Iftikar HussainPosted Jul 21, 2013, 11:43 PM
infoproduct.productId = decProduct;
Regards,
Iftikar
Bineesh ViswanathPosted Jul 21, 2013, 11:33 PM
I found that the value of productId is 0 when breakpoint came in it. see the form;
Please help me to get the result
Iftikar HussainPosted Jul 21, 2013, 12:25 AM
sqlCmd.Parameters.AddWithValue("@productId", infoProduct.productId);
Regards,
Iftikar
Bineesh ViswanathPosted Jul 20, 2013, 9:21 AM
I tried as per your suggestion.
see the code's value during execution of ProductEdit Function ;
The breakpoint not enterring to the messagebox as the value is Zero.
Iftikar HussainPosted Jul 20, 2013, 7:16 AM
int incount = sqlCmd.ExecuteNonQuery();
if (incount > 0)
{
MessageBox.Show("Update Successfully");
}
Regards,
Iftikar
Bineesh ViswanathPosted Jul 20, 2013, 6:38 AM
Iftikar HussainPosted Jul 20, 2013, 4:29 AM
Regards,
Iftikar
Bineesh ViswanathPosted Jul 20, 2013, 3:20 AM
ALTER PROCEDURE productEdit
@productId numeric(18,0),
@productName nvarchar(20),
@purchaseRate numeric(18,0),
@salesRate numeric(18,0)
AS
UPDATE tbl_Product
SET productName =@productName, purchaseRate =@purchaseRate, salesRate =@salesRate where productId=@productId
Iftikar HussainPosted Jul 20, 2013, 3:12 AM
Regards,
Iftikar
Iftikar HussainPosted Jul 20, 2013, 2:58 AM
Please provide the SP details of productEdit
Regards,
Iftikar