By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,591 Members | 647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,591 IT Pros & Developers. It's quick & easy.

Systax Error (Missing Operator)

P: 33
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
Expand|Select|Wrap|Line Numbers
  1. Private Sub loadrecord()
  2.  
  3.  
  4.         Dim conn As New OleDbConnection(Get_Constring)
  5.         Dim cmd As New OleDbCommand
  6.         Dim dr As OleDbDataReader
  7.  
  8.         Try
  9.             conn.Open()
  10.             cmd.Connection = conn
  11.             cmd.CommandType = CommandType.Text
  12.             cmd.CommandText = "select id, First_Name, Last_Name from table1 where id= " & Me.txtFname.Tag
  13.             dr = cmd.ExecuteReader
  14.  
  15.  
  16.  
  17.             If dr.HasRows Then
  18.                 While dr.Read
  19.                     Me.txtFname.Tag = dr("ID")
  20.                     Me.txtFname.Text = IIf(Not IsDBNull(dr("First_name")), dr("First_name"), "")
  21.                     Me.txtFname.Text = IIf(Not IsDBNull(dr("last_name")), dr("last_name"), "")
  22.  
  23.                 End While
  24.  
  25.  
  26.             End If
  27.         Catch ex As Exception
  28.             MsgBox(ErrorToString)
  29.         Finally
  30.             conn.Close()
  31.         End Try
  32.  
  33.  
  34.  
  35.  
  36.     End Sub
  37.  
  38.  

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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Load_Record()
  2.         Dim conn As New OleDbConnection
  3.         Dim cmd As New OleDbCommand
  4.         Dim dr As OleDbDataReader
  5.  
  6.         Try
  7.  
  8.             conn = New OleDbConnection(Get_Constring)
  9.             conn.Open()
  10.             cmd.Connection = conn
  11.             cmd.CommandType = CommandType.Text
  12.             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
  13.  
  14.             dr = cmd.ExecuteReader
  15.             If dr.HasRows Then
  16.                 While dr.Read
  17.                     Me.txtFirstName.Tag = dr("contact_id")
  18.                     Me.txtFirstName.Text = IIf(Not IsDBNull(dr("first_name")), dr("first_name"), "")
  19.                     Me.txtLastName.Text = IIf(Not IsDBNull(dr("last_name")), dr("last_name"), "")
  20.                     Me.txtMidName.Text = IIf(Not IsDBNull(dr("mid_name")), dr("mid_name"), "")
  21.                     If Not IsDBNull(dr("birth_date")) Then
  22.                         Me.dtpDOB.Format = DateTimePickerFormat.Short
  23.                         Me.dtpDOB.Value = dr("birth_date")
  24.                     End If
  25.                     If Not IsDBNull(dr("gender")) Then
  26.                         If dr("gender") = 1 Then
  27.                             Me.optMale.Checked = True
  28.                         Else
  29.                             Me.optFemale.Checked = True
  30.                         End If
  31.                     End If
  32.                     Me.txtHomeAdr.Text = IIf(Not IsDBNull(dr("home_adr")), dr("home_adr"), "")
  33.                     Me.txtBusAdr.Text = IIf(Not IsDBNull(dr("bus_adr")), dr("bus_adr"), "")
  34.                     Me.txtTelNo.Text = IIf(Not IsDBNull(dr("tel_no")), dr("tel_no"), "")
  35.                     Me.txtMobNo.Text = IIf(Not IsDBNull(dr("mobile_no")), dr("mobile_no"), "")
  36.                     Me.txtEmail.Text = IIf(Not IsDBNull(dr("email")), dr("email"), "")
  37.                 End While
  38.             End If
  39.  
  40.         Catch ex As Exception
  41.             MsgBox(ErrorToString)
  42.         Finally
  43.             conn.Close()
  44.         End Try
  45.     End Sub
  46.  
  47.  
  48.  
Thanks . ill be attaching my sample work here.
Attached Files
File Type: zip CRUD.zip (94.7 KB, 35 views)
Oct 14 '14 #1

✓ answered by iam_clint

you are selecting id but trying to get ID, not sure but probably a case sensitivity issue there.
Expand|Select|Wrap|Line Numbers
  1. select id, 
  2.  Me.txtFname.Tag = dr("ID")
  3.  
IIF stands for inline if.
http://msdn.microsoft.com/en-us/libr...=vs.90%29.aspx

dbnull
http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

tag
http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

Share this Question
Share on Google+
1 Reply


iam_clint
Expert 100+
P: 1,208
you are selecting id but trying to get ID, not sure but probably a case sensitivity issue there.
Expand|Select|Wrap|Line Numbers
  1. select id, 
  2.  Me.txtFname.Tag = dr("ID")
  3.  
IIF stands for inline if.
http://msdn.microsoft.com/en-us/libr...=vs.90%29.aspx

dbnull
http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

tag
http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx
Oct 14 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.