【发布时间】:2014-06-16 21:20:32
【问题描述】:
我有一个包含 6 个字符串的数据集。如何用数据集中的这些字符串填充字符串数组。我想象循环遍历数据集。
我有一个问答课。
这里是填充数据集的代码。
SqlConnection connect = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand();
command.Connection = connect;
command.CommandType = CommandType.Text;
command.CommandText = "Select * from Questions";
SqlDataAdapter dataapt = new SqlDataAdapter(command);
DataSet questions = new DataSet();
try
{
connect.Open();
dataapt.Fill(questions, "Questions");
}
这是我的测验课
public class Quiz
{
public string[] questions { get; set; }
public string[] answers { get; set; }
public Quiz()
{
questions = new string[] { "First", "Second", "Third", "Fourth","Fifth","sixth" };
answers = new string[] { "First", "Second", "Third", "Fourth", "Fifth", "sixth" };
}
是否可以从数据集中填充数组??
【问题讨论】:
-
是的。让我们试试吧!
标签: c# asp.net arrays dataset sqlclient