 |
|
ดึงข้อมูลจาก oracle มาเก็บใน datatable แล้วต้องการ insert ข้อมูลนั้นลง sql sever โดย type เป็น datetime |
|
 |
|
|
 |
 |
|
datetimepicker.value.tostring("yyyy/MM/dd")
yyyy = ปี ตัวเลข 4 หลัก
MM = เดือน ตัวเลข 2 หลัก
dd = วันที่ 2 หลัก
ถ้ามีปัญหา ติดตรงไหน เอารูปที่ error มาโพสให้ดูเลยครับจะได้แก้ถูกตรงประเด็น 
|
 |
 |
 |
 |
Date :
2013-05-29 09:56:08 |
By :
01000010 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วค่ะ ใช้แบบนี้
Code (VB.NET)
Dim dateval As DateTime
dateval = Convert.ToDateTime(DataTable.Rows(intRow)(8).ToString())
Dim dateval1 As DateTime
dateval1 = Convert.ToDateTime(DataTable.Rows(intRow)(9).ToShortDateString())
แต่ติดปัญหาคือพอ insert ตัว dateval1 เป็น 2013-05-02
แต่อยากให้มัน insert เป็น 02/05/2013 อ่ะค่ะ อยากทราบว่าควรเพิ่ม code อย่างไรดีค่ะ
|
 |
 |
 |
 |
Date :
2013-05-29 10:29:33 |
By :
khawoat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
dateval1 = Convert.ToDateTime(DataTable.Rows(intRow)(9).ToShortDateString("dd/MM/yyyy"))
|
 |
 |
 |
 |
Date :
2013-05-29 10:57:06 |
By :
CPU4Core |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มัน เออเรอร์ว่า Conversion from string "dd/MM/yyyy" to type 'Integer' is not valid. อ่ะค่ะ
|
 |
 |
 |
 |
Date :
2013-05-29 11:03:31 |
By :
khawoat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โทดทีครับ พิมพ์ผิด ผมว่าน่าจะเป็นอันนี้นะ
Code (VB.NET)
dateval1 = Convert.ToDateTime(DataTable.Rows(intRow)(9).ToString("dd/MM/yyyy"))
|
 |
 |
 |
 |
Date :
2013-05-29 11:20:08 |
By :
CPU4Core |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2013-05-29 13:15:58 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เออเรอร์เหมือนเดิมค่ะ เลยเปลี่ยนไปใช้วิธี format ในคำสั่ง queryเลย ใน where คือ
(CONVERT (varchar(10), date_applied, 103) between '01/04/2013' AND '01/05/2013')
เพื่อที่จะหาค่าระหว่าง แต่เหมือนค่าที่ได้ จำนวน row จะออกแค่ข้อมูลของ 01/04/2013 และ '01/05/2013 เท่านั้น ไม่เป็นค่าระหว่าง ไม่รู้จะทำไงดี ช่วยแนะนำหน่อยนะค่ะ
|
 |
 |
 |
 |
Date :
2013-05-29 13:29:42 |
By :
khawoat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอดูคำสั่งในโปรแกรม หรือคำสั่งquery หน่อยสิครับ
|
 |
 |
 |
 |
Date :
2013-05-29 13:34:25 |
By :
01000010 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คำสั่ง insert to sql
Dim dateval As DateTime
dateval = Convert.ToDateTime(DataTable.Rows(intRow)(8).ToString())
Dim dateval1 As DateTime
dateval1 = Convert.ToDateTime(DataTable.Rows(intRow)(9).ToShortDateString())
Dim strSQL As String = "INSERT INTO inventory_transaction(part_no,contract,location_no,serial_no,transection,voucher_no,voucher_type,COST,dated,date_applied,direction,qty_reversed,quantity,status_code,transaction_code,condition_code,location_group) VALUES('" + DataTable.Rows(intRow)(0).ToString() + "','" + DataTable.Rows(intRow)(1).ToString() + "','" + DataTable.Rows(intRow)(2).ToString() + "','" + DataTable.Rows(intRow)(3).ToString() + "','" + DataTable.Rows(intRow)(4).ToString() + "','" + DataTable.Rows(intRow)(5).ToString() + "','" + DataTable.Rows(intRow)(6).ToString() + "','" + DataTable.Rows(intRow)(7).ToString() + "','" + dateval + "','" + dateval1 + "','" + DataTable.Rows(intRow)(10).ToString() + "','" + DataTable.Rows(intRow)(11).ToString() + "','" + DataTable.Rows(intRow)(12).ToString() + "','" + DataTable.Rows(intRow)(13).ToString() + "','" + DataTable.Rows(intRow)(14).ToString() + "','" + DataTable.Rows(intRow)(15).ToString() + "','" + DataTable.Rows(intRow)(16).ToString() + "')"
Dim sqlComm As New SqlCommand(strSQL.ToString(), connection)
Response.Write(strSQL.ToString())
sqlComm.ExecuteNonQuery()
sqlComm.Dispose()
intRow = CInt(intRow + 1)
คำสั่ง query หาข้อมูลระหว่างวันที่
Dim FIRST_DATE As String = lblSTdate.Text.ToString()
Dim LAST_DATE As String = lblENdate.Text.ToString()
Dim QueryString As New StringBuilder()
QueryString.Append("SELECT part_no, sum(quantity) as quantity")
QueryString.Append(" FROM inventory_transaction ")
QueryString.Append(" WHERE ( transaction_code = 'WOISS' OR transaction_code = 'INTSHIP' OR transaction_code = 'OESHIP') AND (part_no LIKE 'M%' OR part_no LIKE 'G%' OR part_no LIKE 'O-L%') AND (CONVERT (varchar(10), date_applied, 103) BETWEEN ('" + LAST_DATE + "') AND ('" + FIRST_DATE + "')) group by part_no ")
Dim sqlAdapter As New SqlDataAdapter(QueryString.ToString(), connection)
Dim DataTable As New DataTable("TestTable")
sqlAdapter.Fill(DataTable)
|
 |
 |
 |
 |
Date :
2013-05-29 14:42:04 |
By :
khawoat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|