|
 |
|
สอบถามหน่อยครับเรื่องการเพิ่ม insert วันที่เข้าไปใน Database |
|
 |
|
|
 |
 |
|
ผมต้องการเพิ่มวันที่เข้าไปทุกๆครั้งที่มีการกดบันทึกลงใน Database ช่วยแนะนำหน่อยครับ
ด้านล่างเป็น code การกดบันทึกข้อมูลลง DB
Code (C#)
private void save_data_Click(object sender, EventArgs e)
{
string StrQuery;
using (SqlConnection conn = new SqlConnection(connecting))
{
using (SqlCommand comm = new SqlCommand())
{
comm.Connection = conn;
conn.Open();
for (int i = 0; i < dataGridView1.Rows.Count-1; i++)
{
StrQuery = @"INSERT INTO short_data_pm (PARTNAME, CODE, STEP, PROCESS,TOTAL_LAST,TOTAL_CURRENT,LENGTH_ALERT,SUM_TOTAL) VALUES ('" + dataGridView1.Rows[i].Cells[1].Value + "','" + dataGridView1.Rows[i].Cells[2].Value + "', '" + dataGridView1.Rows[i].Cells[3].Value + "', '" + dataGridView1.Rows[i].Cells[4].Value + "', '" + dataGridView1.Rows[i].Cells[5].Value + "', '" + dataGridView1.Rows[i].Cells[6].Value + "', '" + dataGridView1.Rows[i].Cells[7].Value + "', '" + dataGridView1.Rows[i].Cells[8].Value + "', '" + dataGridView1.Rows[i].Cells[9].Value +"');";
comm.CommandText = StrQuery;
comm.ExecuteNonQuery();
}
conn.Close();
}
}
}
Tag : .NET, Ms SQL Server 2008, Win (Windows App)

|
ประวัติการแก้ไข 2019-08-01 10:18:41
|
 |
 |
 |
 |
Date :
2019-08-01 10:17:22 |
By :
newclaffly |
View :
690 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คอลัมน์วันที่มันอยู่ไหนครับ
ถ้ารู้ก็แค่ เพิ่ม เป็น datatime.now หรืออะไรที่มันเป็น type เดียวกัน ครับ
|
 |
 |
 |
 |
Date :
2019-08-01 14:21:40 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับผมตอนนี้ทำได้แล้วครับ
|
 |
 |
 |
 |
Date :
2019-08-01 14:56:09 |
By :
newclaffly |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code
private void save_data_Click(object sender, EventArgs e)
{
string StrQuery;
using (SqlConnection conn = new SqlConnection(connecting))
{
using (SqlCommand comm = new SqlCommand())
{
comm.Connection = conn;
conn.Open();
for (int i = 0; i < dataGridView1.Rows.Count-1; i++)
{
StrQuery = @"INSERT INTO short_data_pm (PARTNAME, CODE, STEP, PROCESS,TOTAL_LAST,TOTAL_CURRENT,LENGTH_ALERT,SUM_TOTAL,CREATE_DATE)
VALUES ('" + dataGridView1.Rows[i].Cells[1].Value + "','" + dataGridView1.Rows[i].Cells[2].Value + "', '" + dataGridView1.Rows[i].Cells[3].Value + "', '" + dataGridView1.Rows[i].Cells[4].Value + "', '" +
dataGridView1.Rows[i].Cells[5].Value + "', '" + dataGridView1.Rows[i].Cells[6].Value + "', '" + dataGridView1.Rows[i].Cells[7].Value + "', '" + dataGridView1.Rows[i].Cells[8].Value + "', '" + dataGridView1.Rows[i].Cells[9].Value +"',GETDATE());";
comm.CommandText = StrQuery;
comm.ExecuteNonQuery();
}
conn.Close();
}
}
}
|
 |
 |
 |
 |
Date :
2019-08-06 17:07:06 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|