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. empty string

empty string

Scheduled Pinned Locked Moved C#
debuggingquestion
4 Posts 3 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.
  • R Offline
    R Offline
    realmontanakid
    wrote on last edited by
    #1

    Hi I got following function. When I debug the code '"+Name+"' is Name="System.Data.DataRowView". Does anybody knows why? private void menuItem1_Select(object sender, System.EventArgs e) { string Name = this.listBox1.SelectedItem.ToString(); OleDbConnection conn = new OleDbConnection(connString); OleDbCommand dbCommand = new OleDbCommand("SELECT Beschreibung FROM tbl_T5 WHERE (Rechner = '"+Name+"')", conn); conn.Open(); OleDbDataReader dbReader; dbReader = dbCommand.ExecuteReader(); dbReader.Read(); if (dbReader.HasRows) { this.menuItem2.Text = dbReader["Beschreibung"].ToString(); } dbReader.Close(); conn.Close(); }

    M 1 Reply Last reply
    0
    • R realmontanakid

      Hi I got following function. When I debug the code '"+Name+"' is Name="System.Data.DataRowView". Does anybody knows why? private void menuItem1_Select(object sender, System.EventArgs e) { string Name = this.listBox1.SelectedItem.ToString(); OleDbConnection conn = new OleDbConnection(connString); OleDbCommand dbCommand = new OleDbCommand("SELECT Beschreibung FROM tbl_T5 WHERE (Rechner = '"+Name+"')", conn); conn.Open(); OleDbDataReader dbReader; dbReader = dbCommand.ExecuteReader(); dbReader.Read(); if (dbReader.HasRows) { this.menuItem2.Text = dbReader["Beschreibung"].ToString(); } dbReader.Close(); conn.Close(); }

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      That's quite easy: Name is set at exactly one location, so the value you see is the result of this.listBox1.SelectedItem.ToString();. That means the selected item in your listBox1 is a DataRowView. DataRowView doesn't have an overloaded ToString method, so you simply get the type name. But what's the question? Obviously you expect Name to be something else. Could it be that you don't want one of listBox1's items? Without further info we can only guess... mav

      E 1 Reply Last reply
      0
      • M mav northwind

        That's quite easy: Name is set at exactly one location, so the value you see is the result of this.listBox1.SelectedItem.ToString();. That means the selected item in your listBox1 is a DataRowView. DataRowView doesn't have an overloaded ToString method, so you simply get the type name. But what's the question? Obviously you expect Name to be something else. Could it be that you don't want one of listBox1's items? Without further info we can only guess... mav

        E Offline
        E Offline
        ESTAN
        wrote on last edited by
        #3

        Try replace this.listBox1.SelectedItem.ToString(); by this.listBox1.SelectedItem.Text;

        R 1 Reply Last reply
        0
        • E ESTAN

          Try replace this.listBox1.SelectedItem.ToString(); by this.listBox1.SelectedItem.Text;

          R Offline
          R Offline
          realmontanakid
          wrote on last edited by
          #4

          got it.. DataRowView dv =(DataRowView)this.listBox1.SelectedItem; this.menuItem2.Text = dv["Beschreibung"].ToString(); Thank you

          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