Hi guys,
am having trouble with this error code while trying to insert certain values to the database. Can somebody help?
am having trouble with this error code while trying to insert certain values to the database. Can somebody help?
Code:
if (e.ColumnIndex == 4)
{
try{
string id = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
string item = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
string quantity = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
string UnitCost = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
int quant = int.Parse(quantity);
double unicost = double.Parse(UnitCost);
double tot=quant*unicost;
try
{
MySqlConnection connection = new MySqlConnection(Generals.ConnectionString);
connection.Open();
string sql = "INSERT INTO sales VALUES ('" + id + "','" + item + "','" + quant + "','" + unicost + "','" + DateTime.Now.ToString() + "','"+tot+"')";
MySqlCommand cmd = new MySqlCommand(sql, connection);
cmd.ExecuteNonQuery();
connection.Close();
MessageBox.Show("New Sales is added successfully", "Hotel Management", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Refresh();
Comment