|
 |
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
|
|
 |
กระทู้ #3513 [Vb] (จาก IP: 110.171.44.215)
ช่วยหน่อยคะ อยากทำ Auto-number พอเปลี่ยนเดือนใหม่แล้วให้รันที่ 0001 ใหม่คะ
ทำแบบให้ autorun ได้แล้วแต่เหลือเพียงให้เวลาขึ้นเดือนใหม่ ให้เป็น 0001 คะ
|
จากคุณ
:
Miint / gfocemoobin@gmail.com [2014-05-05 09:18:37]
|
|
ความคิดเห็น #29045 (จาก IP: 110.171.44.215)
Code Class GenID +++++++++++++++++++++++++++++ Public Function AutoGenerateID(ByVal _sTable As String, ByVal _sColumn As String, ByVal _sJOBLOGIDNAME As String, ByVal _sJOBYEAR As String, ByVal _sJOBMONTH As String) As String Dim strConn As String strConn = connection.StrConn With Conn If .State = ConnectionState.Open Then .Close() .ConnectionString = strConn .Open() Dim oledb As String
Dim oledbresult As Integer oledb = "SELECT Count(" + _sJOBLOGIDNAME + ") FROM " + _sTable + ""
Try
Dim Mycmd As New OleDbCommand(oledb, Conn) Myreader = Mycmd.ExecuteReader() Myreader.Read()
oledbresult = CInt(Myreader.Item(0)) Myreader.Close() AutoGenerateID = Format(oledbresult + 1, "0000")
Catch ex As Exception AutoGenerateID = "0001" End Try End With
End Function |
จากคุณ
:
Miint / gfocemoobin@gmail.com [2014-05-05 11:37:13]
|
 |
ความคิดเห็น #29046 (จาก IP: 110.171.44.215)
Page load ++++++++++++++++++++++ Public Class creat Inherits System.Web.UI.Page Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Payuda\Documents\Database2.mdb" Dim da As New OleDbDataAdapter Dim ds As New DataSet Dim Cn As New OleDbConnection(strConn) Dim sGenID As GenID = New GenID Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Cn = New OleDbConnection(strConn) Cn.Open() Dim sGenID As GenID
TextBox1.Text = AutoGenID()
End Sub
Public Function AutoGenID() As String
Dim GCLTID As String Dim CLTID As String Dim ids As String Dim sTable As String Dim sColumn As String Dim sJOBLOGIDNAME As String Dim sJOBYEAR As String Dim sJOBMONTH As String
sTable = "JOBLOG" sColumn = "JOBLOGID" sJOBLOGIDNAME = "JOBLOGIDNAME" sJOBYEAR = "JOBYEAR" sJOBMONTH = "JOBMONTH" GCLTID = sGenID.AutoGenerateID(sTable, sColumn, sJOBLOGIDNAME, sJOBYEAR, sJOBMONTH) Dim sYear As String = Year(Now).ToString("0000") Dim sMonth As String = Month(Now).ToString("00") CLTID = "JLG-" & sYear & sMonth & GCLTID Return CLTID
End Function |
จากคุณ
:
Miint / gfocemoobin@gmail.com [2014-05-05 11:38:40]
|
 |
ความคิดเห็น #29047 (จาก IP: 110.171.44.215)
ตอนนี้แปลงโค้ดใหม่แล้วค่ะ พอเปลี่ยนเดือนใหม่รัน 0001 ใหม่แล้ว แต่พอสร้างงานอันต่อไปมันไม่รัน 0002 อะคะ<br>==========================<br>Public Class GenID<br> Dim Conn As New OleDbConnection<br> Dim com As OleDbCommand<br> Dim da As OleDbDataAdapter<br> Dim ds As New DataSet<br> Dim Myreader As OleDbDataReader<br> Public Function AutoGenerateID(ByVal _sTable As String, ByVal _sColumn As String, ByVal _sJOBLOGIDNAME As String) As String<br> Dim strConn As String<br> strConn = connection.StrConn<br> With Conn<br> If .State = ConnectionState.Open Then .Close()<br> .ConnectionString = strConn<br> .Open()<br> Dim oledb As String<br> Dim cMonth As String = \ |
จากคุณ
:
Miint / gfocemoobin@gmail.com [2014-05-05 17:02:28]
|
 |
ความคิดเห็น #29048 (จาก IP: 110.171.44.215)
ตอนนี้แปลงโค้ดใหม่แล้วค่ะ พอเปลี่ยนเดือนใหม่รัน 0001 ใหม่แล้ว แต่พอสร้างงานอันต่อไปมันไม่รัน 0002 อะคะ ************************** Public Class GenID Dim Conn As New OleDbConnection Dim com As OleDbCommand Dim da As OleDbDataAdapter Dim ds As New DataSet Dim Myreader As OleDbDataReader Public Function AutoGenerateID(ByVal _sTable As String, ByVal _sColumn As String, ByVal _sJOBLOGIDNAME As String) As String Dim strConn As String strConn = connection.StrConn With Conn If .State = ConnectionState.Open Then .Close() .ConnectionString = strConn .Open() Dim oledb As String Dim cMonth As String = "JLG-" & Date.Now.Year.ToString("0000") & Date.Now.Month.ToString("00")
Dim oledbresult As Integer oledb = "SELECT max(" + _sJOBLOGIDNAME + ") FROM " + _sTable + ""
Try
Dim Mycmd As New OleDbCommand(oledb, Conn) Myreader = Mycmd.ExecuteReader() Myreader.Read() 'AutoGenerateID = Myreader.Item(0).ToString.Substring(0, 10) 'AutoGenerateID = cMonth.Substring(0, 10) 'AutoGenerateID = Myreader.Item(0).ToString.Substring(10, 4) If Myreader.Item(0).ToString.Substring(0, 10) <> cMonth.Substring(0, 10) Then AutoGenerateID = cMonth & Format(oledbresult + 1, "0000") Else 'oledbresult = CInt(Myreader.Item(0)) 'oledbresult = CInt(oledbresult + 1) 'AutoGenerateID = oledbresult.ToString("0000") AutoGenerateID = Myreader.Item(0) End If
Myreader.Close() Catch ex As Exception AutoGenerateID = cMonth & Format(oledbresult + 1, "0000")
End Try End With
End Function
End Class |
จากคุณ
:
Miint / gfocemoobin@gmail.com [2014-05-05 17:04:05]
|
 |
ความคิดเห็น #29049 (จาก IP: 110.171.44.215)
ทำได้แล้วคะ เอามาแปะไว้เพื่อเป็นประโยชน์กับคนอื่นๆ ========================= Public Function AutoGenerateID(ByVal _sTable As String, ByVal _sColumn As String, ByVal _sJOBLOGIDNAME As String) As String Dim strConn As String strConn = connection.StrConn With Conn If .State = ConnectionState.Open Then .Close() .ConnectionString = strConn .Open() Dim oledb As String Dim cMonth As String = "JLG-" & Date.Now.Year.ToString("0000") & Date.Now.Month.ToString("00") Dim oledbresult As Integer oledb = "SELECT max(" + _sJOBLOGIDNAME + ") FROM " + _sTable + "" Try Dim Mycmd As New OleDbCommand(oledb, Conn) Myreader = Mycmd.ExecuteReader() Myreader.Read() If Myreader.Item(0).ToString.Substring(0, 10) <> cMonth.Substring(0, 10) Then AutoGenerateID = cMonth & Format(oledbresult + 1, "0000") Else oledbresult = CInt(Myreader.Item(0).ToString.Substring(10, 4)) AutoGenerateID = cMonth & Format(oledbresult + 1, "0000") End If Myreader.Close() Catch ex As Exception AutoGenerateID = cMonth & Format(oledbresult + 1, "0000")
End Try End With
End Function |
จากคุณ
:
Miint / gfocemoobin@gmail.com [2014-05-06 08:58:02]
|
 |
ความคิดเห็น #29050 (จาก IP: 58.8.2.149)
คือว่าอาจจากคำถามก็ไม่เข้าใจว่าต้องการสื่ออะไร และแม้กระทั่งตอบแล้ว ผมก็ไม่เข้าใจ แต่ก็เห็นว่า มีการใส่เงื่อนไขการทำงานเพิ่มเข้าไป ก็อยากแนะนำว่า อาจไม่ต้องยกโค้ดจริงมา แค่หยิบมาเฉพาะโค้ดที่ต้องการ เช่น เดิมทำงานจากโค้ดนี้ได้ผลยังไง แต่ต้องการให้ได้ผลยังไง น่าจะทำให้ต่อไปผมถ้าพอช่วยได้จะได้ช่วย
สุดท้ายคือการบ่นให้คนอื่นฟัง มันไม่เกิดประโยชน์เท่ากับการที่อธิบายให้คนอื่นฟังว่ากำลังเกิดปัญหาอะไร และต้องการแก้ไข |
จากคุณ
:
maddog [2014-05-06 15:49:49]
|
 |
ความคิดเห็น #29051 (จาก IP: 110.171.44.215)
ขอโทษด้วยคะ มือใหม่หัดทำ อธิบายไม่ค่อยถูก ก็เลยทำได้แค่นี้คะ |
จากคุณ
:
Miint / gfocemoobin@gmail.com [2014-05-06 16:21:10]
|
 |
ความคิดเห็น #29052 (จาก IP: 61.90.38.237)
มันเป็นปัญหาของทั้งมือใหม่ และมือเก่าครับ คือการอธิบายปัญหา ให้คนอื่นเข้าใจ มันยากกว่าการแก้ไขเองด้วยซ้ำ
ทำให้คนที่เค้าอยากจะช่วยไม่เข้าใจคำถาม บางคนอาจถามว่า "สรุปถามว่าอะไร" หรือ บางคนก็เงียบไม่ตอบ ทำให้เสียโอกาสที่จะได้รับความช่วยเหลือ |
จากคุณ
:
maddog [2014-05-07 09:32:56]
|
 |
|
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
|
|
|
|
|