开发者

C# Read rows from a table and store the values in a string[]

I am using C# and ASP.NEt to create a web application where I need to insert/view data. I created my own class that stores values for a "Ticket" or a support ticket. My question is, how can I grab the values from the SQL table with the tickets and store them in the Ticket cl开发者_JAVA技巧ass? I don't need the specifics, just what SQL class I should use and how to store them.

Thanks!


Several options: ADO.NET to query the data using the SqlConnection and SqlDataAdapter, filling the results for a DataTable, and copying the data row data to your Ticket class.

Or even better, use LINQ to SQL or ADO.NET Entity Framework. Plenty of examples of all of this online.


This tutorial should get you started: http://www.csharp-station.com/Tutorials/ADODotNet/Lesson02.aspx

In the section that reads:

while (rdr.Read())
{
     Console.WriteLine(rdr[0]);
}

You will want replace the Console.WriteLine() with code to to create new instances of Ticket and add them to a ticket list.


You should be able to use a SqlDataReader to get your data, get your column data and place it into your string array.


Have you considered using an ORM? Entity Framework is one the most used.

See this tutorial for more information:

http://www.codeproject.com/Articles/363040/An-Introduction-to-Entity-Framework-for-Absolute-B

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜