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 HussainRank #423 · 5.9K reputationPosted Jul 19, 2013, 10:58 PM EDT
Please provide the SP details of productEdit
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 19, 2013, 11:12 PM EDT
Regards,
Iftikar
Bineesh ViswanathRank #1,681 · 907 reputationPosted Jul 19, 2013, 11:20 PM EDT
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 HussainRank #423 · 5.9K reputationPosted Jul 20, 2013, 12:29 AM EDT
Regards,
Iftikar
Bineesh ViswanathRank #1,681 · 907 reputationPosted Jul 20, 2013, 2:38 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 20, 2013, 3:16 AM EDT
int incount = sqlCmd.ExecuteNonQuery();
if (incount > 0)
{
MessageBox.Show("Update Successfully");
}
Regards,
Iftikar
Bineesh ViswanathRank #1,681 · 907 reputationPosted Jul 20, 2013, 5:21 AM EDT
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 HussainRank #423 · 5.9K reputationPosted Jul 20, 2013, 8:25 PM EDT
sqlCmd.Parameters.AddWithValue("@productId", infoProduct.productId);
Regards,
Iftikar
Bineesh ViswanathRank #1,681 · 907 reputationPosted Jul 21, 2013, 7:33 PM EDT
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 HussainRank #423 · 5.9K reputationPosted Jul 21, 2013, 7:43 PM EDT
infoproduct.productId = decProduct;
Regards,
Iftikar
Bineesh ViswanathRank #1,681 · 907 reputationPosted Jul 21, 2013, 7:58 PM EDT
If you have any other method to update this form, please send me immediately
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 21, 2013, 8:05 PM EDT
Regards,
Iftikar
Bineesh ViswanathRank #1,681 · 907 reputationPosted Jul 21, 2013, 8:34 PM EDT
public partial class frmProduct : Form
{
decimal decProduct;
public frmProduct()
{
InitializeComponent();
}
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 21, 2013, 8:48 PM EDT
Regards,
Iftikar