|
I get this error:
Error
occurred, customer data could not be updated: No value given for one or more
required parameters.
What have I not done right?
Here is the code:
private void btnCapUpdate_Click(object sender, System.EventArgs e)
{
// Set up variables
double d1, d2, d3, d4, d5, d6, sum1, sum2, sum3, sum4, sum5;
//Get the selected company name from combobox and assign to variable
string strCoyName = selCompany.SelectedItem.ToString();
// Convert textbox values to double and assign to variables
d1 = Convert.ToDouble(txtStckQty.Text);
d2 = Convert.ToDouble(txtStckPrice.Text);
d3 = Convert.ToDouble(txtBondQty.Text);
d4 = Convert.ToDouble(txtBondPrice.Text);
d5 = Convert.ToDouble(txtPrefStckQty.Text );
d6 = Convert.ToDouble(txtPrefStckPrice.Text);
// Do the calculation
sum1 = d1 * d2;
sum2 = d3 * d4;
sum3 = d5 * d6;
sum4 = sum2 + sum3;
sum5 = sum1 + sum4;
// Convert back to string and display in text boxes
txtStckMktVal.Text = Convert.ToString(sum1);
txtBondValue.Text = Convert.ToString(sum2);
txtPrefStckValue.Text = Convert.ToString(sum3);
txtOtherIssuesVal.Text = Convert.ToString(sum4);
txtTotalCap.Text = Convert.ToString(sum5);
// Set up DB connection parameters and open it
OleDbCommand myOleDbCommand = new OleDbCommand();
myOleDbConn.Open();
myOleDbCommand.Connection = myOleDbConn;
// Update DB with new figures from calculation
myOleDbCommand.CommandText = "UPDATE
CapitalizationTbl SET capComStckQty = '" + d1
+ "', capComStckPrice ='"+d2+"',
capComMktValue ='"+sum1+"', capBondQty ='"+d3
+"', capBondPrice ='"+d4+"',
capBondValue ='"+sum2+"', capPrefQty ='"+d5
+"', capPrefPrice ='"+d6+"',
capPrefVal ='"+sum3+"', capOtherVal ='"+sum4
+"', capGrandTotal ='"+sum5+"'
WHERE coyName = '"+strCoyName+"'";
try
{
myOleDbCommand.ExecuteNonQuery();
MessageBox.Show("Customer data updated!");
}
// Catch any errors
catch(OleDbException ex)
{
MessageBox.Show("Error occurred, customer data could
not be updated:" + ex.Message);
}
finally
{
//Close the connection if it is open
if (myOleDbConn.State==ConnectionState.Open)
{
myOleDbConn.Close();
}
}
}
Please help me somebody. I have tried all I know; I am new to C#
|