如果日期早于 12 日,则以格式在文本框中输入日期时,DD/MM/YYYY
它将存储为MM/DD/YYYY
. 我需要将其存储为类型。
protected void InsertButton_Click(object sender, EventArgs e)
{
Int32 claim = (Int32)Session["Claim"];
string claim1 = Convert.ToString(claim);
Label4.Text = "Claim Number : " + (String)claim1;
Label4.Visible = true;
// declare variables to hold info enterend by user
string expenseType;
string purpose;
decimal amount;
DateTime date;
Boolean receipts;
//assign info entered to variables entered above
expenseType = DropDownList1. Text;
purpose = PurposeofExpenseTextBox.Text;
amount = Convert.ToDecimal(AmountSpentTextBox.Text);
date = Convert.ToDateTime(DatePurchasedTextBox.Text);
receipts = CheckBox1.Checked;
DateTime today = DateTime.Today;
// create connection string "conn"
string mapPath = Server.MapPath(".");
string ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;" +
@"Data source= "*****";
OleDbConnection conn = new OleDbConnection(ConnectionString);
try
{
//create query to insert values into Expenses table
OleDbCommand cmd = new OleDbCommand("INSERT INTO Expenses (ExpenseType, PurposeofExpense, AmountSpent, DatePurchased, strEmpName, Receipts, EmployeeID, ExpNumber) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", conn);
cmd.Parameters.Add("@ExpenseType", OleDbType.VarChar).Value = DropDownList1.Text;
cmd.Parameters.Add("@PurposeofExpense", OleDbType.VarChar).Value = PurposeofExpenseTextBox.Text;
cmd.Parameters.Add("@AmountSpent", OleDbType.VarChar).Value = AmountSpentTextBox.Text;
cmd.Parameters.Add("@DatePurchased", OleDbType.VarChar).Value = DatePurchasedTextBox.Text;
cmd.Parameters.Add("@strEmpName", OleDbType.VarChar).Value = (String)Session["New"];
cmd.Parameters.Add("@Receipts", OleDbType.Boolean).Value = CheckBox1.Checked;
cmd.Parameters.Add("@EmployeeID", OleDbType.VarChar).Value = (String)Session["Number"];
cmd.Parameters.Add("@ExpNumber", OleDbType.VarChar).Value = (Int32)Session["Claim"];
//open connection "conn"
conn.Open();
//execute insert query
cmd.ExecuteNonQuery();