tags:

views:

102

answers:

3

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 class? I don't need the specifics, just what SQL class I should use and how to store them.

Thanks!

+3  A: 

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.

Brian
+1, nice start, Brian!
Rubens Farias
+1  A: 

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.

Phil Sandler
A: 

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

Rubens Farias