Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. help in OleDbDataReader

help in OleDbDataReader

Scheduled Pinned Locked Moved C#
csharphelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hassanasp
    wrote on last edited by
    #1

    i want to convert this vb.net code to c# code but i have problem with oledbdatareader i have missing code or i cannot convert this line into C# Me.Label1.Text = reader.Item(0).ToString. code with vb is working code: Dim con As New OleDbConnection Dim scom As New OleDbCommand Dim reader As OleDbDataReader While reader.Read Me.Label1.Text = reader.Item(0).ToString End While code with c# is not working missing line scom.Parameters.AddWithValue("@A", textBox1.Text); scom.CommandText = "Select Name from Table1 where (id=@A)"; scom.CommandType = CommandType.Text; scom.Connection = conn; OleDbDataReader reader = scom.ExecuteReader(); while (reader.Read()=true) { label1.Text= reader.; //probem is here coannot found item() }; property item(0) not found in C# code can any one help me

    Ahmed hassan

    W 1 Reply Last reply
    0
    • H hassanasp

      i want to convert this vb.net code to c# code but i have problem with oledbdatareader i have missing code or i cannot convert this line into C# Me.Label1.Text = reader.Item(0).ToString. code with vb is working code: Dim con As New OleDbConnection Dim scom As New OleDbCommand Dim reader As OleDbDataReader While reader.Read Me.Label1.Text = reader.Item(0).ToString End While code with c# is not working missing line scom.Parameters.AddWithValue("@A", textBox1.Text); scom.CommandText = "Select Name from Table1 where (id=@A)"; scom.CommandType = CommandType.Text; scom.Connection = conn; OleDbDataReader reader = scom.ExecuteReader(); while (reader.Read()=true) { label1.Text= reader.; //probem is here coannot found item() }; property item(0) not found in C# code can any one help me

      Ahmed hassan

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      hassanasp wrote:

      cannot convert this line into C# Me.Label1.Text = reader.Item(0).ToString

      If you're using indexers in vb they are in parenthesis but in c# they are in []. So have a try with

      Label1.Text = reader.Item[0].ToString

      hassanasp wrote:

      while (reader.Read()=true)

      In C# equality is == so:

      while (reader.Read()==true)

      or

      while (reader.Read())

      The need to optimize rises from a bad design.My articles[^]

      H 1 Reply Last reply
      0
      • W Wendelius

        hassanasp wrote:

        cannot convert this line into C# Me.Label1.Text = reader.Item(0).ToString

        If you're using indexers in vb they are in parenthesis but in c# they are in []. So have a try with

        Label1.Text = reader.Item[0].ToString

        hassanasp wrote:

        while (reader.Read()=true)

        In C# equality is == so:

        while (reader.Read()==true)

        or

        while (reader.Read())

        The need to optimize rises from a bad design.My articles[^]

        H Offline
        H Offline
        hassanasp
        wrote on last edited by
        #3

        the problem is when write(reader.)no property item found in C# but in vb is found label1.Text = reader.Item[0].ToString; Error 1 'System.Data.OleDb.OleDbDataReader' does not contain a definition for 'Item'

        Ahmed hassan

        W 1 Reply Last reply
        0
        • H hassanasp

          the problem is when write(reader.)no property item found in C# but in vb is found label1.Text = reader.Item[0].ToString; Error 1 'System.Data.OleDb.OleDbDataReader' does not contain a definition for 'Item'

          Ahmed hassan

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          Item property isn't language specific. It exists in the framework, not in the language see: OleDbDataReader.Item Property (Int32)[^]. One problem you have is that ToString is a method so it must have parenthesis so:

          label1.Text = reader.Item[0].ToString();

          or

          label1.Text = reader[0].ToString();

          The need to optimize rises from a bad design.My articles[^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups