 |
|
สอบถามเรื่อง set date format datagridview ครับ vb |
|
 |
|
|
 |
 |
|
คือตอนนี้ใน database ตังค่า ให้เป็น short
แต่พอคิวรี่เข้า datagridview แล้วมัน ดันมีเวลาขึ้นมาด้วยซึ่งผมไม่ต้อการให้มีเวลาปรากฎ
ใน database 1/2/2013 แต่ใน datagridview เป้น 1/2/2013 00.00.00 ครับ
ต้องการให้ แสดงเป็น 1/2/2013 เหมืนใน database ครับ
Code (VB.NET)
Dim connection As New OleDbConnection(con)
connection.Open()
Dim myTable As DataTable = New DataTable("MyTable")
myTable.Columns.Add(New DataColumn("date"))
myTable.Columns.Add(New DataColumn("product"))
myTable.Columns.Add(New DataColumn("channel"))
myTable.Columns.Add(New DataColumn("position"))
myTable.Columns.Add(New DataColumn("Impression"))
myTable.Columns.Add(New DataColumn("Impression to use"))
myTable.Columns.Add(New DataColumn("impression/now"))
Dim sdate As Date
Dim edate As Date
sdate = CType(DateTimePicker1.Text, Date)
edate = CType(DateTimePicker2.Text, Date)
Try
'Add columns and column names to the datatable
Dim cmd As OleDbCommand = New OleDbCommand("SELECT ch_day,P_name,ch_name,ch_posi,imp_total,imp_use,imp_now FROM Impress WHERE (Impress.ch_day>=#" & sdate & "# And Impress.ch_day<=#" & edate & "#)And (P_name='" & cbo_web.Text & "')And(ch_name='" & cbo_ch.Text & "')And(ch_posi='" & cbo_posi.Text & "') order by ch_id", connection)
Dim dr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.Default)
Dim myRow As DataRow
While dr.Read()
myRow = myTable.NewRow
myRow.Item(0) = dr(0) 'We add the 1st value of the row to our 1st column of the datatable
myRow.Item(1) = dr(1)
myRow.Item(2) = dr(2)
myRow.Item(3) = dr(3)
myRow.Item(4) = dr(4)
myRow.Item(5) = dr(5)
myRow.Item(6) = dr(6)
myTable.Rows.Add(myRow)
End While
dr.Close()
'Add datatable to datagridview
Dim myData4 As DataTable = myTable
ds = New DataSet()
ds.Tables.Add(myData4)
DataGridView1.DataSource = myData4
connection.Close()
Catch ErrProcess As Exception
' MsgBox(ex.ToString) 'Show error when something goes wrong
MessageBox.Show("ไม่สามารถคำนวณImpression จากรายการที่ท่านเลือก เนื่องจาก " & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End Try
Tag : .NET, Ms Access, VBScript, VB.NET, VS 2012 (.NET 4.x)
|
|
 |
 |
 |
 |
Date :
2013-01-31 14:27:19 |
By :
ืnotanimore |
View :
2798 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าเอาให้ง่าย ก็จัดตั้งแต่ใน sql เลยครับ ให้ออกมาเป็นรูปแบบที่ต้องการ
|
 |
 |
 |
 |
Date :
2013-01-31 14:31:28 |
By :
zero1150kfc |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เขียนยังไงครับ
|
 |
 |
 |
 |
Date :
2013-01-31 15:30:23 |
By :
ืnotanimore |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
วิธีแปลงฟอร์แมทให้เป็น datetime ตั้งแต่ตอนเขียน SQL นะครับ
Code (VB.NET)
Dim cmd As OleDbCommand = New OleDbCommand("SELECT CONVERT(VARCHAR, ch_day, 103),P_name,ch_name,ch_posi,imp_total,imp_use,imp_now FROM Impress WHERE (Impress.ch_day>=#" & sdate & "# And Impress.ch_day<=#" & edate & "#)And (P_name='" & cbo_web.Text & "')And(ch_name='" & cbo_ch.Text & "')And(ch_posi='" & cbo_posi.Text & "') order by ch_id", connection)
ลองดูรหัสฟอร์แมทวันที่ได้จากที่นี่ครับ
http://www.w3schools.com/sql/func_convert.asp
|
 |
 |
 |
 |
Date :
2013-01-31 16:40:44 |
By :
eibwenmai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|