3

Right now I have a Select Tag retrieving all the Title of the documents from the Database:

string QueryString = "SELECT TITLE FROM DOC";
SqlConnection myconnection = new SqlConnection(ConnectString);
SqlDataAdapter mycommand = new SqlDataAdapter(QueryString,myconnection);
DataSet ds = new DataSet();
mycommand.Fill(ds, "DOC");

test.DataSource = ds;
test.DataTextField = "TITLE";
test.DataValueField = "TITLE";
test.DataBind();

The problem is that I need to store all this data in text so that I can use the MailMessage Class and send it via Email.

Any Thoughts?

3
  • can you describe more? what did you mean by all data? in your example, you just use the title and bind it to a dropdown, you need more information? or you need some structural data such as list<string(title)>? your end user has to choose at least one title is it correct? Commented Sep 28, 2018 at 15:15
  • @AlirezaYadegari I'm creating a system that Select all the Titles of the documents and send only the titles of the documents everyday via Email. So I need to use the MailMessage Class and SMTP Client to send. The problem is that the 'Body' of the email only accepts Text. So I created a ListBox that retrieves all titles from my Database and I need to store all the data that I received from my List in Text, in my Textbox (input tag), the user has no interaction. Commented Sep 28, 2018 at 15:24
  • ok, I just can't understand the last step, you have whatever you want in the server, why you need al data into a textbox? you can do it like this string.join(",",datatable.AsEnumerable().select(x => x.Filed<string>("title"))) and now you have your string and i need to pass this string as your body message .for sending email if you have static template i suggest create HTML file and read it from File.ReadAllText and replace create the string which I describe it above and inside wherever you want. am I Understand your question right? Commented Sep 28, 2018 at 15:35

1 Answer 1

1

You can convert DataSet to list

var titleList = ds.Tables[0].AsEnumerable()
.Select(dr => new {Name = dr.Field<string>("TITLE")}).ToList();

Then you can concatenate it into single string:

var titles = titleList.Aggregate((current, next) => current + ", " + next);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer, I just didn't understand this part: (current, next) => current + ", " + next);
As I understand, you need to get get string with all the titles. Aggregate concatenate all the string values from the list. You can read detailed explanation here stackoverflow.com/questions/7105505/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.