having problem in inserting in access database
I am having problem in inserting and updating into access database.It showing the following message "Syntax error in UPDATE statement" and for insert "Syntax error in INSERT INTO statement". I have a dropdownlist id=listcolour, the item selected from dropdownlist will be inserted into the database. I am giving the progarm for ur reference. the language used is C#
protected void btninsert_Click(object sender, EventArgs e)
{
string insertSql = "INSERT INTO wire_master(product_code, description, colour, opening_stock, rate, value, unit) VALUES('" + txtpcode.Text + "','" + txtdescription.Text + "','" + listcolour.SelectedItem.Text + "','" + txtopstock.Text + "','" + txtrate.Text + "','" + txtvalue.Text + "','" + txtunit.Text + "')";
con = new OleDbConnection(constr);
cmd = new OleDbCommand(insertSql, con);
cmd.CommandType = CommandType.Text;
int added = 0;
try
{
con.Open();
added = cmd.ExecuteNonQuery();
result.Text = "<b>" + added.ToString() + "</b>" + " record added.";
}
catch (Exception ex)
{
result.Text = "<b>Error in entering data. </b>" + ex.Message;
}
finally
{
con.Close();
}
}
protected void btnupdate_Click(object sender, EventArgs e)
{
string updateSql = "UPDATE wire_master SET description='" + txtdescription.Text + "', colour='" + listcolour.SelectedItem.Text + "', opening_stock='" + txtopstock.Text + "', rate='" + txtrate.Text + "', value='" + txtvalue.Text + "', unit='" + txtunit.Text + "' WHERE product_code='" + txtpcode.Text + "'";
con = new OleDbConnection(constr);
cmd = new OleDbCommand(updateSql, con);
cmd.CommandType = CommandType.Text;
int updated = 0;
try
{
con.Open();
updated = cmd.ExecuteNonQuery();
result.Text = "<b>" + updated.ToString() + "</b>" + "<b> record updated.</b>";
}
catch (Exception ex)
{
result.Text = "<b>Error updating database.</b>" + ex.Message;
}
finally
{
con.Close();
}
}
Plz solve the problem.
|