none
DataRow problem RRS feed

  • Question

  • Hi!

    I tried to find a solution  for  my problem in other posts but I couldn't find an answer, so here goes:

    I have a DataTable Pricetable (priceID, veicleID, price).
    With Select statment i want to find a row with price=5.000 and then from this row get the veicleID.

    DataRow[] foundRows;
                        foundRows = zbirka_podatkov1DataSet.Tables["Pricetable"].Select("price=5000");
                        MessageBox.Show(foundRows[1].ToString());  // This should display veicleID field's value...

    Instead of veicleID i get message:  projectFolder.zbirka_podatkov1DataSet+PricetableRow.

    What am I doing wrong?  Please help.


     


    Monday, August 6, 2007 12:18 PM

Answers

  • Try this then:

     

    partial class zbirka_podatkov1DataSet

    {

        partial class PricetableRow

        {

            public override string ToString()

             {

                return System.String.Format("{0} - {1}, {2}",

                                    this.priceID.ToString(),

                                    this.vehicleID.ToString(),

                                    this.price.ToString());

             }

        }

    }
    Tuesday, August 7, 2007 11:09 AM

All replies

  • What you are seeing is the default behavior for the ToString() method. If you want your class to print a more informative message, you will have to override the base implementation of ToString() in your PricetableRow class.

     

    Right-click on your DataSet designer and choose "View Code." Then add the following partial class definition to your DataSet definition:

     

    partial class zbirka_podatkov1DataSet

    {

        partial class PricetableRow

        {

            public override string ToString()

             {

                return String.Format("{0} - {1}, {2}",

                                    this.priceID.ToString(),

                                    this.vehicleID.ToString(),

                                    this.price.ToString());

             }

        }

     

    Monday, August 6, 2007 12:43 PM
  • When I try to implement the code, it shows Error: "The name 'String' does not exist in the current context", and underlines the String in return sentance.  

    Monday, August 6, 2007 1:13 PM
  • Try this then:

     

    partial class zbirka_podatkov1DataSet

    {

        partial class PricetableRow

        {

            public override string ToString()

             {

                return System.String.Format("{0} - {1}, {2}",

                                    this.priceID.ToString(),

                                    this.vehicleID.ToString(),

                                    this.price.ToString());

             }

        }

    }
    Tuesday, August 7, 2007 11:09 AM
  • Next time just use lower case 's' for string instead of upper case 'S' for String.  That way you don't have to access the System object and it does the same thing.

     

    Tuesday, August 7, 2007 12:46 PM
  • Thank you for that. I'm generally not a C# programmer.

    Tuesday, August 7, 2007 2:26 PM
  • Heh, no problem, the only reason I know right off the top of my head is because I want to Captilize the String and run into it all the time.

     

     

    Tuesday, August 7, 2007 2:29 PM
  • Thanks guys, it's working great
    Tuesday, August 7, 2007 2:51 PM