 |
|
สร้างตัวแปร รับค่า DateTime วันเวลาปัจจุบัน แล้ว Insert ลง DB ทำยังไงครับ C#.NET |
|
 |
|
|
 |
 |
|
ฐานข้อมูลเป็น DateTime อ่ะครับ Format คือ yyyy-mm-dd H:i:s
ต้องทำไงอ่ะครับ
Code (C#)
// จะสร้างตัวแปรรับตัวแปรรับ DateTime
d = ..............
// Insert
MySqlCommand SelectCommand1 = new MySqlCommand("INSERT INTO finalproject.topup (date,amount,userID,staffID) VALUES ('" ................ + "','" + this.numericUpDown1.Text + "','" + this.label1.Text + "','" + this.label12.Text + "');", myConn);
Tag : .NET, Win (Windows App), C#, VS 2012 (.NET 4.x)
|
ประวัติการแก้ไข 2014-07-21 04:06:04
|
 |
 |
 |
 |
Date :
2014-07-21 01:11:56 |
By :
jpong7 |
View :
2352 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
INSERT ได้แล้วครับ แต่ทำไมมัน INSERT เป็น พ.ศ. อ่ะครับ ทำให้เป็น ค.ศ. ยังไงอ่ะครับ
Code (C#)
MySqlCommand SelectCommand1 = new MySqlCommand("INSERT INTO finalproject.topup (date,amount,userID,staffID) VALUES ('"+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"','" + this.numericUpDown1.Text + "','" + this.label1.Text + "','" + this.label12.Text + "');", myConn);

|
ประวัติการแก้ไข 2014-07-21 01:20:50
 |
 |
 |
 |
Date :
2014-07-21 01:19:21 |
By :
jpong7 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปลี่ยน Format ที่เครื่องครับ
โดยเข้าไปที่ Control Panel เลือก Region คลิกที่ Additional setting.... ดูที่แท็บด้านบน คลิ้กเลือกที่ Date ...
ดูที่ Calendar type ด้านล่าง เลือกรูปแบบที่ตามที่ต้องการครับ

|
 |
 |
 |
 |
Date :
2014-07-21 02:27:05 |
By :
Zakariya |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|