hi im reinventing a code myself but when i tried to run it didnt work as expected. i dont want to copy all the one ive downloaded so i made it a smaller by reducing the control use and not using search command.
so heres my very simple code
just to be honest with you, i dont understand the tag property there and some other stuff like the IIF and IsDBNull.
heres the source code i am using as my reference.
Thanks . ill be attaching my sample work here.
so heres my very simple code
Code:
Private Sub loadrecord()
Dim conn As New OleDbConnection(Get_Constring)
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
Try
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "select id, First_Name, Last_Name from table1 where id= " & Me.txtFname.Tag
dr = cmd.ExecuteReader
If dr.HasRows Then
While dr.Read
Me.txtFname.Tag = dr("ID")
Me.txtFname.Text = IIf(Not IsDBNull(dr("First_name")), dr("First_name"), "")
Me.txtFname.Text = IIf(Not IsDBNull(dr("last_name")), dr("last_name"), "")
End While
End If
Catch ex As Exception
MsgBox(ErrorToString)
Finally
conn.Close()
End Try
End Sub
just to be honest with you, i dont understand the tag property there and some other stuff like the IIF and IsDBNull.
heres the source code i am using as my reference.
Code:
Private Sub Load_Record()
Dim conn As New OleDbConnection
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
Try
conn = New OleDbConnection(Get_Constring)
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "select contact_id, last_name, first_name, mid_name, birth_date, gender, home_adr, bus_adr, tel_no, mobile_no, email from tblAddressBook where contact_id= " & Me.txtFirstName.Tag
dr = cmd.ExecuteReader
If dr.HasRows Then
While dr.Read
Me.txtFirstName.Tag = dr("contact_id")
Me.txtFirstName.Text = IIf(Not IsDBNull(dr("first_name")), dr("first_name"), "")
Me.txtLastName.Text = IIf(Not IsDBNull(dr("last_name")), dr("last_name"), "")
Me.txtMidName.Text = IIf(Not IsDBNull(dr("mid_name")), dr("mid_name"), "")
If Not IsDBNull(dr("birth_date")) Then
Me.dtpDOB.Format = DateTimePickerFormat.Short
Me.dtpDOB.Value = dr("birth_date")
End If
If Not IsDBNull(dr("gender")) Then
If dr("gender") = 1 Then
Me.optMale.Checked = True
Else
Me.optFemale.Checked = True
End If
End If
Me.txtHomeAdr.Text = IIf(Not IsDBNull(dr("home_adr")), dr("home_adr"), "")
Me.txtBusAdr.Text = IIf(Not IsDBNull(dr("bus_adr")), dr("bus_adr"), "")
Me.txtTelNo.Text = IIf(Not IsDBNull(dr("tel_no")), dr("tel_no"), "")
Me.txtMobNo.Text = IIf(Not IsDBNull(dr("mobile_no")), dr("mobile_no"), "")
Me.txtEmail.Text = IIf(Not IsDBNull(dr("email")), dr("email"), "")
End While
End If
Catch ex As Exception
MsgBox(ErrorToString)
Finally
conn.Close()
End Try
End Sub
Comment