|
|
|
อยากสอบถามเกี่ยวกับการบันทึก ปี ลง sql ช่วยทีครับผม |
|
|
|
|
|
|
|
Code (C#)
DateTime date = Convert.ToDateTime(TextBox1.Text, System.Globalization.CultureInfo("th-TH"));
string sql = "INSERT INTO [MYTABLE] ([MYDATE]) VALUES (@MyDate)";
SqlCommand command = new SqlCommand(sql, conn);
command.Parameters.AddWithValue("@MyDate", date);
conn.Open();
command.ExecuteNonQuery();
conn.Close();
|
|
|
|
|
Date :
2014-04-10 10:16:36 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองแบบนี้ดูครับ
protected void btnSave_Click(Object sender, EventArgs e)
{
try
{
CultureInfo us = new CultureInfo("en-US");
DateTime dt = UtillHelper.Convert2RadDateDisplay(txtOrderDate.Text);
DateTime datetime = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, us.Calendar);
String xDate = datetime.ToShortDateString();
}
catch (Exception ex)
{
throw ex;
}
}
public static DateTime ConvertDateDisplay(string input)
{
try
{
string xInput = input.Replace("/", "");
DateTime lc_Datetime = new DateTime(Convert.ToInt16(getCrisYear(xInput.Substring(4, 4))), Convert.ToInt16(xInput.Substring(2, 2)), Convert.ToInt16(xInput.Substring(0, 2)));
return lc_Datetime;
}
catch (Exception ex)
{
throw new Exception("Incorrect date format.");
}
}
public static int getCrisYear(int NumberYear)
{
int tmpYear = 0;
if (NumberYear > 2500 && NumberYear != 9999)
{
tmpYear = NumberYear - 543;
}
else
{
tmpYear = NumberYear;
}
return tmpYear;
}
|
|
|
|
|
Date :
2014-04-10 11:02:42 |
By :
ABC |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณทุกๆท่านครับ ^^
|
|
|
|
|
Date :
2014-04-10 13:18:18 |
By :
Patoo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|