try
{
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = @"myconnectionstring_blah_blah";
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "INSERT INTO StaffOrders (StaffID, OrderDate, Pants, Boots " + "VALUES (@StaffID, @OrderDate, @Pants, @Boots)";
command.Parameters.AddWithValue("@StaffID", staffid);
command.Parameters.AddWithValue("@OrderDate", datenow);
command.Parameters.AddWithValue("@Pants", pant);
command.Parameters.AddWithValue("@Boots", boot);
command.Connection = connection;
connection.Open();
command.ExecuteNonQuery();
//**********************************************************
if(int.Parse(bootsissued) > 0)
{
//Update LastBoot in StaffList with today's Date
}
//***********************************************************
connection.Close();
}
catch //blah blah
I have two access tables:
StaffList:
ID (autonumber - pk - unique)
StaffID (indexed unique string)
LastBoot (Date/Time)
...
StaffOrders:
ID (autonumber - pk - unique)
StaffID (indexed unique string) - same as above
... (pants, boots, etc)
I'm inserting records into StaffOrders
, but I want to update the record LastBoot
(from StaffList
) with the current date, anytime a boot is ordered.
Both tables are in the same access database. I have no problem adding the order records, but I can't seem to UPDATE
the LastBoot
record with the current date.
The unique identifier I have to UPDATE
the appropriate record is StaffID
not the ID
autonumber.
DateTime datenow = DateTime.Today;
string myconnectionstring = @"//connectionstring";
OleDbConnection myconnection = new OleDbConnection();
myconnection.ConnectionString = myconnectionstring;
try
{
myconnection.Open();
ConnectedIcons();
OleDbCommand command = new OleDbCommand();
command.Connection = myconnection;
string update = "UPDATE StaffList SET LastBoot = '" + datenow + "' WHERE StaffID = '" + selectedstaffid + "';";
var accessUpdateCommand = new OleDbCommand(update, myconnection);
accessUpdateCommand.Parameters.AddWithValue("LastBoot", datenow);
accessUpdateCommand.Parameters.AddWithValue("StaffID", selectedstaffid);
command = accessUpdateCommand;
command.ExecuteNonQuery();
myconnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
/* I actually just missed the ' marks before my variables in my string update */
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.