|
-
June 5th, 2008, 07:12 PM
#1
c# database help
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();
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|