please tell me where am i wrong

try
            {
                OleDbCommand cmd = new OleDbCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "insert into purchase(pdate,bill id,ritem,suppname,smobno,qty,rate,amount,payment,balance) Values('" +
                    dateTimePicker1.Text.ToString() + "','" + textBox15.Text.ToString() + "','" + textBox7.Text.ToString() + "','" + textBox12.Text.ToString() + "','" + comboBox2.Text.ToString() + "','" + textBox14.Text.ToString() + "','" + textBox13.Text.ToString() + "','" + textBox11.Text.ToString() + "','" + textBox8.Text.ToString() + "','" + textBox10.Text.ToString() + "')";
                cmd.Connection = conn;
                conn.Open();
                //MessageBox.Show("insert into purchase(pdate,bill id,ritem,suppname,smobno,qty,rate,amount,payment,balance) Values('" +
                  //  dateTimePicker1.Text + "','" + textBox15.Text + "','" + textBox7.Text + "','" + textBox12.Text + "','" + comboBox2.Text + "','" + textBox14.Text + "','" + textBox13.Text + "','" + textBox11.Text + "','" + textBox8.Text + "','" + textBox10.Text + "');");
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

Recommended Answers

All 2 Replies

Check here, how you need to do Insertions into Access dataBase (using OleDb commands).

i think this is what you need.... :p

open your own oledb connection then in the button edit the code below.. :v

cmd = new OleDbCommand("insert into Users(firstname,lastname,username,[password],weight,height,age,BMI,gender,illness1)" + "values(" + "'" + textBox6.Text + "'" + "," + "'" + textBox7.Text + "'" + "," + "'" + textBox1.Text + "'" + "," + "'" + textBox2.Text + "'" + "," + "'" + textBox4.Text + "'" + "," + "'" + textBox3.Text + "'" + "," + "'" + textBox5.Text + "'" + "," + "'" + bmires2 + "'" + "," + "'" + "M" + "'" + "," + "'" + "hypertension" + "'" + ")", conn);
            cmd.ExecuteNonQuery();
            MessageBox.Show("record has been added", "records");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.