Click to See Complete Forum and Search --> : c# database help


mike.dh.mount
June 5th, 2008, 07:12 PM
I've been working on this for days. I can't seem to insert into my access db. here is my code. When the code is run, the "YEAH!!!" message is displayed, but no new record in the db. Any help would be fantastic.


string conString ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\BT1.mdb;providerName=System.Data.OleDb";
OleDbConnection BoardConnection = new OleDbConnection(conString);

try
{

OleDbCommand cmd = new OleDbCommand("INSERT INTO tblBoards (BoardName, BoardSerial, BoardOpened, EmpOpened, BoardPos) values (@BoardName, @BoardSerial, @BoardOpened, @EmpOpened, @BoardPos)", BoardConnection);



cmd.Parameters.Add("@BoardName", OleDbType.VarChar).Value = varBoardNames;
cmd.Parameters.Add("@BoardSerial", OleDbType.VarChar).Value = varBoardSers;
cmd.Parameters.Add("@BoardOpened", OleDbType.DBDate).Value = varBoardOpen;
cmd.Parameters.Add("@EmpOpened", OleDbType.VarChar).Value = "mike";
cmd.Parameters.Add("@BoardPos", OleDbType.Integer).Value = varBoardPos;


BoardConnection.Open();
int numRows = cmd.ExecuteNonQuery();
BoardConnection.Close();
if (numRows == 1)
{

MessageBox.Show("YEAH!!!");
}
else
{

MessageBox.Show("****");
}


}
catch (Exception e)
{ }

finally
{
if (BoardConnection != null)
{
BoardConnection.Close();
}
}

dglienna
June 5th, 2008, 07:52 PM
This doesn't return any rows

int numRows = cmd.ExecuteNonQuery();

You'll have to check afterwords to see if its there.

I wonder about the |Data Directory| statement

string conString ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\BT1.mdb;providerName=System.Data.OleDb";