c#从表中读取行并将值存储在字符串[]中

时间:2021-11-27 21:23:08

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.

我正在使用c#和ASP。NEt创建一个需要插入/查看数据的web应用程序。我创建了自己的类,它存储“Ticket”或支持票的值。我的问题是,如何从带有票据的SQL表中获取值并将它们存储在Ticket类中?我不需要细节,只需要使用什么SQL类以及如何存储它们。

Thanks!

谢谢!

4 个解决方案

#1


1  

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

本教程将帮助您入门: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.

您将需要用代码替换Console.WriteLine()来创建票据的新实例并将它们添加到票据列表中。

#2


3  

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.

几个选项:ADO。NET使用SqlConnection和SqlDataAdapter查询数据,填充数据表的结果,并将数据行数据复制到您的Ticket类。

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

或者更好,使用LINQ来SQL或ADO。净实体框架。网上有很多这样的例子。

#3


0  

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

您应该能够使用SqlDataReader获取数据、获取列数据并将其放置到字符串数组中。

#4


0  

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

你考虑过使用ORM吗?实体框架是最常用的。

See this tutorial for more information:

更多信息请参见本教程:

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

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

#1


1  

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

本教程将帮助您入门: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.

您将需要用代码替换Console.WriteLine()来创建票据的新实例并将它们添加到票据列表中。

#2


3  

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.

几个选项:ADO。NET使用SqlConnection和SqlDataAdapter查询数据,填充数据表的结果,并将数据行数据复制到您的Ticket类。

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

或者更好,使用LINQ来SQL或ADO。净实体框架。网上有很多这样的例子。

#3


0  

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

您应该能够使用SqlDataReader获取数据、获取列数据并将其放置到字符串数组中。

#4


0  

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

你考虑过使用ORM吗?实体框架是最常用的。

See this tutorial for more information:

更多信息请参见本教程:

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

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