Problem in inserting data into AccessDB

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi,

I am trying to insert a record to a table in my local AccessDB through
CSharp. I dont get any error when i execute the program. But after i
insert, the table is not getting updated. Below is the code which i
use to insert

private void button2_Click(object sender, EventArgs e)
{
DataTable dt = LoadDT();
string SQL = "Select * from Ticket_Charging_Setting where
charge = 0 ";
OleDbConnection oConnection = new
OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\
\AFC_ATM.MDB");
try
{
oConnection.Open();
OleDbDataAdapter oAdapter = new
OleDbDataAdapter(SQL,oConnection);
oAdapter.InsertCommand = new OleDbCommand("insert into
Ticket_Charging_Setting(ticket_type_code,charge) " +
"values(@str1,@str2)");
oAdapter.InsertCommand.Parameters.Add("@str1",
OleDbType.VarChar, 1, "F");
oAdapter.InsertCommand.Parameters.Add("@str2",
OleDbType.Integer, 5, "50");
oAdapter.Update(dt);
MessageBox.Show("Success");
}
catch (OleDbException oe)
{
MessageBox.Show("Exception thrown : ",
oe.Errors[0].Message);
}
oConnection.Close();
}
public static DataTable LoadDT()
{
DataTable DT = new DataTable();
string ConnString = "Provider = Microsoft.Jet.OLEDB.4.0;
Data Source = C:\\AFC_ATM.MDB";
string SQL = "Select * from Ticket_Charging_Setting where
charge = 0 ";

OleDbConnection OleConn = new OleDbConnection(ConnString);
OleDbDataAdapter OleAdp = new OleDbDataAdapter(SQL,
OleConn);
OleConn.Open();
OleAdp.Fill(DT);
OleConn.Close();
return DT;
}

Can anyone please guide me what is the problem with the above code?
Thanks in advance!!

Cheers
Hira

.


Quantcast