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