Hi,
I have this code for inserting data in the MS ACCESS database:
command.CommandText = "Insert into PSOSTD ([SMAT11], [SKOM], [KOL], [CEN], [BRP], [DOK],[DATA], [SERBR1], [SERBR2], [MBRK], [IN]) values (?,?,?,?,?,?,?,?,?,?,?)";
command.Parameters.AddWithValue("@SMAT11", comboBox1.Text);
command.Parameters.AddWithValue("@SKOM", comboBox3.Text);
command.Parameters.AddWithValue("@KOL", Convert.ToInt32(textBox4.Text));
command.Parameters.AddWithValue("@CEN", Convert.ToInt32(label15.Text));
command.Parameters.AddWithValue("@BRP", textBox1.Text);
command.Parameters.AddWithValue("@DOK", "4");
command.Parameters.AddWithValue("@DATA", dateTimePicker1.Value.Date);
command.Parameters.AddWithValue("@SERBR1", "");
command.Parameters.AddWithValue("@SERBR2", "");
command.Parameters.AddWithValue("@MBRK", comboBox2.SelectedItem);
if (radioButton1.Checked)
{
command.Parameters.AddWithValue("@IN", "J");
}
else if (radioButton2.Checked)
{
command.Parameters.AddWithValue("@IN", "A");
}
else
{
MessageBox.Show("Nemate izbrano dali kontrolorot e od JSP ili od agencija");
comboBox2.Focus();
}
DataSet1 dset = new DataSet1();
conn.Open();
command.ExecuteNonQuery();
conn.Close();
When debugging, I don't get any error, but it doesn't insert data in the database.
Can anybody help me please?
Thanks
Loading
Suthish NairPosted Sep 13, 2013, 7:37 AM
Suthish NairPosted Sep 12, 2013, 9:47 AM
NelPosted Sep 12, 2013, 6:42 AM
I found my error in the data source (the path) in the ciode where I define the OleDbConnection.
Thanks anyway to both of you
NelPosted Sep 12, 2013, 5:29 AM
OleDbCommand command = new OleDbCommand();
command.Connection = conn;
label12.Text = Convert.ToString(p + 1);
command.CommandText = "Insert into PSOSTD ([SMAT11], [SKOM], [KOL], [CEN], [BRP], [DOK],[DATA], [SERBR1], [SERBR2], [MBRK], [IN]) values (?,?,?,?,?,?,?,?,?,?,?)";
command.Parameters.AddWithValue("@SKOM", comboBox3.Text);
command.Parameters.AddWithValue("@KOL", Convert.ToInt32(textBox4.Text));
command.Parameters.AddWithValue("@CEN", Convert.ToInt32(label15.Text));
command.Parameters.AddWithValue("@BRP", textBox1.Text);
command.Parameters.AddWithValue("@DOK", "4");
command.Parameters.AddWithValue("@DATA", dateTimePicker1.Value.Date);
command.Parameters.AddWithValue("@SERBR1", "");
command.Parameters.AddWithValue("@SERBR2", "");
command.Parameters.AddWithValue("@MBRK", comboBox2.SelectedItem);
if (radioButton1.Checked)
{
command.Parameters.AddWithValue("@IN", "J");
}
else if (radioButton2.Checked)
{
command.Parameters.AddWithValue("@IN", "A");
}
else
{
MessageBox.Show("Nemate izbrano dali kontrolorot e od JSP ili od agencija");
comboBox2.Focus();
}
DataSet1 dset = new DataSet1();
conn.Open();
command.ExecuteNonQuery();
OleDbDataAdapter oleDBDataAdapter1 = new OleDbDataAdapter(new OleDbCommand("Select * from PSOSTD order by SMAT11 asc", conn));
dset.Clear();
oleDBDataAdapter1.Fill(dset, "PSOSTD");
OleDbDataAdapter oleDbAd2 = new OleDbDataAdapter();
oleDbAd2.SelectCommand = new OleDbCommand();
oleDbAd2.SelectCommand.Connection = conn;
oleDbAd2.SelectCommand.CommandText = "SELECT p.BRP, p.SMAT11, m.IMAT, m.EM, p.KOL, m.CEN, MAT.MBR, p.IN from PSOSTD as p, SIFMAT as m, MATDAT AS MAT where p.SMAT11=m.SMAT11 and p.BRP=? order by BRP";
oleDbAd2.SelectCommand.Parameters.AddWithValue("@BRP", textBox1.Text);
oleDbAd2.SelectCommand.ExecuteNonQuery();
dset.Clear();
oleDbAd2.Fill(dset, "PSOSTD?");
dataGridView1.DataSource = dset.Tables["PSOSTD?"].DefaultView;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conn.Close();
}
Posted Sep 12, 2013, 5:01 AM
Pankaj PandeyPosted Sep 12, 2013, 4:58 AM