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. LINQ
  4. LINQ TO SQL CONVERT TO STRING ?? help please simple but complicated!

LINQ TO SQL CONVERT TO STRING ?? help please simple but complicated!

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqdata-structuressales
5 Posts 3 Posters 2 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.
  • W Offline
    W Offline
    wallaq
    wrote on last edited by
    #1

    code is:- protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { MA_TECHDataContext ma10 = new MA_TECHDataContext(); var validity = from c in ma10.customer_infos where c.customer_lname == TextBox2.Text.ToString() select new { c.customer_lname, c.customer_ID }; GridView1.DataSource = validity; GridView1.DataBind(); // TextBox4.Text = Convert.ToString( validity.Single() ); Array ab; ab = validity.ToArray(); TextBox4.Text = ab.GetValue(0).ToString(); well the result in txtbx is :-- { customer_lname = 222 , customer_ID = 2 } yes in curly brackets and all one!!!!!!!!

    N A 2 Replies Last reply
    0
    • W wallaq

      code is:- protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { MA_TECHDataContext ma10 = new MA_TECHDataContext(); var validity = from c in ma10.customer_infos where c.customer_lname == TextBox2.Text.ToString() select new { c.customer_lname, c.customer_ID }; GridView1.DataSource = validity; GridView1.DataBind(); // TextBox4.Text = Convert.ToString( validity.Single() ); Array ab; ab = validity.ToArray(); TextBox4.Text = ab.GetValue(0).ToString(); well the result in txtbx is :-- { customer_lname = 222 , customer_ID = 2 } yes in curly brackets and all one!!!!!!!!

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      There is nothing complicated about it. You are creating an anonymous type, that's how it will display. BTW, TextBox2.Text is a string, you don't need to do TextBox2.Text.ToString(). It's just stupid to do it.


      I know the language. I've read a book. - _Madmatt

      W 1 Reply Last reply
      0
      • N Not Active

        There is nothing complicated about it. You are creating an anonymous type, that's how it will display. BTW, TextBox2.Text is a string, you don't need to do TextBox2.Text.ToString(). It's just stupid to do it.


        I know the language. I've read a book. - _Madmatt

        W Offline
        W Offline
        wallaq
        wrote on last edited by
        #3

        thanks but i know!! how to get it display correctly sir??

        N 1 Reply Last reply
        0
        • W wallaq

          thanks but i know!! how to get it display correctly sir??

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          wallaq wrote:

          thanks but i know!!

          What do yo know?

          wallaq wrote:

          how to get it display correctly

          Define "correctly".


          I know the language. I've read a book. - _Madmatt

          1 Reply Last reply
          0
          • W wallaq

            code is:- protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { MA_TECHDataContext ma10 = new MA_TECHDataContext(); var validity = from c in ma10.customer_infos where c.customer_lname == TextBox2.Text.ToString() select new { c.customer_lname, c.customer_ID }; GridView1.DataSource = validity; GridView1.DataBind(); // TextBox4.Text = Convert.ToString( validity.Single() ); Array ab; ab = validity.ToArray(); TextBox4.Text = ab.GetValue(0).ToString(); well the result in txtbx is :-- { customer_lname = 222 , customer_ID = 2 } yes in curly brackets and all one!!!!!!!!

            A Offline
            A Offline
            Andreas X
            wrote on last edited by
            #5

            First of all. converting a single object to an array just to collect the first element in the array. is pointless. so remove the lines:

            Array ab;

            ab = validity.ToArray();
            TextBox4.Text = ab.GetValue(0).ToString();

            I don't understand what you are trying to to. do you want to have the same text in TextBox4 as in TextBox2 ????? in that case:

            TextBox4.Text = validity.Select(s=>s.customer_lname).FirstOrDefault();

            if you want the customerID in TextBox4:

            TextBox4.Text = validity.Select(s=>s.customer_ID).FirstOrDefault().ToString();

            kind regards

            Andreas Johansson
            IT Professional at Office IT Partner i Norrbotten Sweden
            What we don't know. We learn.
            What you don't know. We teach

            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