Private Sub txtsearch_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.EditValueChanged
Try
If GridView1.RowCount <> 0 Then
If GridView1.GetDataRow(GridView1.FocusedRowHandle)("User_id").ToString = "" Then
Exit Sub
Else
Dim pic As Byte()
sb = New StringBuilder
sb.Append("SELECT * FROM V_USER_TH")
sb.Append(" WHERE user_id ='" & sendpara.user_id & "'")
connection()
da = New SqlDataAdapter(sb.ToString, conn)
ds = New DataSet
conn.Close()
da.Fill(ds, "V_USER_TH")
TextEdit3.Text = ds.Tables("V_USER_TH").Rows(0)("Firstname_th").ToString
TextEdit4.Text = ds.Tables("V_USER_TH").Rows(0)("lastname_th").ToString
TextEdit14.Text = ds.Tables("V_USER_TH").Rows(0)("Mobile_phone").ToString
TextEdit9.Text = ds.Tables("V_USER_TH").Rows(0)("Address").ToString
TextEdit10.Text = ds.Tables("V_USER_TH").Rows(0)("Sub_amp").ToString
TextEdit11.Text = ds.Tables("V_USER_TH").Rows(0)("AMP_NAME_TH").ToString
TextEdit12.Text = ds.Tables("V_USER_TH").Rows(0)("PRV_NAME_TH").ToString
TextEdit13.Text = ds.Tables("V_USER_TH").Rows(0)("thai_code").ToString
TextEdit18.Text = ds.Tables("V_USER_TH").Rows(0)("Site_name").ToString
TextEdit17.Text = ds.Tables("V_USER_TH").Rows(0)("Department_Name").ToString
TextEdit16.Text = ds.Tables("V_USER_TH").Rows(0)("Position_name").ToString
TextEdit15.Text = ds.Tables("V_USER_TH").Rows(0)("start_date")
TextEdit25.Text = ds.Tables("V_USER_TH").Rows(0)("status").ToString
Select Case TextEdit25.Text
Case "F"
TextEdit25.Text = "พนักงานประจำ"
Case "P"
TextEdit25.Text = "พนักงานทดลองงาน"
Case "T"
TextEdit25.Text = "ฝึกงาน"
End Select
CalcDate(ds.Tables("V_USER_TH").Rows(0)("start_date"), Today.Date)
TextEdit22.Text = vYears
TextEdit23.Text = vMonths
TextEdit24.Text = vDays
pic = ds.Tables("V_USER_TH").Rows(0)("Pic_user")
Dim mem As New MemoryStream(pic)
PictureEdit1.Image = Image.FromStream(mem)
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End Try
End Sub
ใส่ IF ds.Tables("V_USER_TH").Rows.Count > 0 Then ไม่ได้เหรอครับ
Code (VB.NET)
Private Sub txtsearch_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.EditValueChanged
Try
If GridView1.RowCount <> 0 Then
If GridView1.GetDataRow(GridView1.FocusedRowHandle)("User_id").ToString = "" Then
Exit Sub
Else
Dim pic As Byte()
sb = New StringBuilder
sb.Append("SELECT * FROM V_USER_TH")
sb.Append(" WHERE user_id ='" & sendpara.user_id & "'")
connection()
da = New SqlDataAdapter(sb.ToString, conn)
ds = New DataSet
conn.Close()
da.Fill(ds, "V_USER_TH")
IF ds.Tables("V_USER_TH").Rows.Count > 0 Then
TextEdit3.Text = ds.Tables("V_USER_TH").Rows(0)("Firstname_th").ToString
TextEdit4.Text = ds.Tables("V_USER_TH").Rows(0)("lastname_th").ToString
TextEdit14.Text = ds.Tables("V_USER_TH").Rows(0)("Mobile_phone").ToString
TextEdit9.Text = ds.Tables("V_USER_TH").Rows(0)("Address").ToString
TextEdit10.Text = ds.Tables("V_USER_TH").Rows(0)("Sub_amp").ToString
TextEdit11.Text = ds.Tables("V_USER_TH").Rows(0)("AMP_NAME_TH").ToString
TextEdit12.Text = ds.Tables("V_USER_TH").Rows(0)("PRV_NAME_TH").ToString
TextEdit13.Text = ds.Tables("V_USER_TH").Rows(0)("thai_code").ToString
TextEdit18.Text = ds.Tables("V_USER_TH").Rows(0)("Site_name").ToString
TextEdit17.Text = ds.Tables("V_USER_TH").Rows(0)("Department_Name").ToString
TextEdit16.Text = ds.Tables("V_USER_TH").Rows(0)("Position_name").ToString
TextEdit15.Text = ds.Tables("V_USER_TH").Rows(0)("start_date")
TextEdit25.Text = ds.Tables("V_USER_TH").Rows(0)("status").ToString
Select Case TextEdit25.Text
Case "F"
TextEdit25.Text = "พนักงานประจำ"
Case "P"
TextEdit25.Text = "พนักงานทดลองงาน"
Case "T"
TextEdit25.Text = "ฝึกงาน"
End Select
CalcDate(ds.Tables("V_USER_TH").Rows(0)("start_date"), Today.Date)
TextEdit22.Text = vYears
TextEdit23.Text = vMonths
TextEdit24.Text = vDays
pic = ds.Tables("V_USER_TH").Rows(0)("Pic_user")
Dim mem As New MemoryStream(pic)
PictureEdit1.Image = Image.FromStream(mem)
End IF
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End Try
End Sub