Protected Sub GenOrderID()
Dim dv As DataView
Dim sql As String = "Select Max(Right(staff_id,4)) as staff_id from tb_staff"
dv = ObjDb.GetDataSet(sql).Tables(0).DefaultView
'dv.Table(tb_staff)
If Not dv.Count > 0 Then
'ถ้าค่าที่ได้รับเป็นค่า Null
' MsgBox("ok")
'MsgBox(Now.ToString("yy"))
txtstaff_id.Text = "S" & "001"
Else
Dim newID As Integer = CInt(dv.Equals("staff_id"))
newID = newID + 1
' MsgBox(newID)
txtstaff_id.Text = "S" & newID.ToString("000")
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
bindposi()
binddepartments()
Me.btnSave.Visible = True
' autoid()
Me.btnCancel.Visible = True
End If
End Sub
Protected Sub SaveData()
Dim sql As String
Dim hbd As String
hbd = Format(cldhbd.SelectedDate.Date, "dd/MM/yyyy")
sql = "INSERT INTO tb_staff(staff_id,login_name,password1,staff_name,email,addr,hbd,tel_staff,pois_id,dept_id)"
sql += " VALUES ('" & Trim(Me.txtstaff_id.Text) & "','" & Trim(Me.txtlogin_name.Text) & "','" & Trim(Me.txtpassword1.Text) & "','" & Trim(Me.txtstaff_name.Text) & "', "
sql += " '" & Trim(Me.txtemail.Text) & "','" & Trim(Me.txtaddr.Text) & "',convert(datetime, '" & hbd & "', 103),'" & Trim(Me.txttel_sff.Text) & "',"
sql += " '" & Trim(Me.ddlposi.SelectedValue) & "','" & Trim(Me.ddldept.SelectedValue) & "') "
Response.Write(sql)
ObjDb.ExecuteNonQuery(sql)
'Response.Redirect("Staff_sh.aspx?staff_id")
End Sub
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
SaveData()
End Sub
Protected Sub autoid()
Dim dv As DataView
Dim sqlTmp As String
sqlTmp = "Select MAX(staff_id) as staff_id from tb_staff"
dv = ObjDb.GetDataSet(sqlTmp).Tables(0).DefaultView
If dv.Count > 0 Then
txtstaff_id.Text = "S" & "001"
Else
Dim newID As Integer = CInt(dv.Equals("staff_id"))
newID += 1
MessageBox.Show(newID)
txtstaff_id.Text = "S" & newID.ToString("000")
End If
End Sub
If dv.Count > 0 Then
txtstaff_id.Text = "S" & "001"
Else
Dim newID As Integer = CInt(dv.Equals("staff_id"))
newID += 1
MessageBox.Show(newID)
txtstaff_id.Text = "S" & newID.ToString("000")
End If
Protected Sub autoid()
Dim dv As DataView
Dim sqlTmp As String
sqlTmp = "Select MAX(staff_id) as staff_id from tb_staff"
dv = ObjDb.GetDataSet(sqlTmp).Tables(0).DefaultView
If txtstaff_id.Text = "S" & "001" Then
' 'txtstaff_id.Text = "S" & "001"
Else
Dim newID As Integer = CInt(dv.Equals("staff_id"))
newID += 1
txtstaff_id.Text = "S" & newID.ToString("000")
End If
End Sub
แบบนี้รึป่าวค่ะ แต่ยังได้ เช่นกันค่ะ
Date :
2013-01-18 13:05:43
By :
keem
No. 9
Guest
ตรง autoid ครับ ลองแบบนี้ครับ
Code (VB.NET)
If dv.Count > 0 Then
Dim newID As Integer = CInt(dv.Equals("staff_id"))
newID += 1
MessageBox.Show(newID)
txtstaff_id.Text = "S" & newID.ToString("000")
Else
txtstaff_id.Text = "S" & "001"
End If