本文介绍了如何将班级列表分解为各个组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将一个类项目并将其插入到MDF文件中。
我无法将List类列表等同于其各个列。
如何将班级列表分解为各自的组件?
I am trying to take a class item and insert it into a MDF file.
I am having trouble equating the "List" classlist to its individual columns.
How do I break classlist down to its individual components?
public class Class1
{
public Int32 id { get; set; }
public string col1 { get; set; }
public string col2 { get; set; }
public string col3 { get; set; }
}
List<Class1> classlist = new List<Class1>();
classlist.Add(new Class1() { id = 1, col1 = "11", col2 = "22", col3="33" });
classlist.Add(new Class1() { id = 2, col1 = "44", col2 = "55", col3="66" });
classlist.Add(new Class1() { id = 3, col1 = "77", col2 = "88", col3="99" });
string connStr = ConfigurationManager.ConnectionStrings["MDFdb"].ConnectionString;
string cmdStr = "INSERT INTO [Table1] (col1,col2,col3) VALUES (@col1,@col2,@col3);";
for (int n; n<25; n++)
{
using (SqlConnection conn = new SqlConnection(connStr))
{
using (SqlCommand cmd = new SqlCommand(cmdStr, conn))
{
conn.Open();
cmd.ExecuteNonQuery();
cmd.Parameters.Add("@col1", classlist[n,1]);
cmd.Parameters.Add("@col2", classlist[n,2]);
cmd.Parameters.Add("@col2", classlist[n,3]);
}
}
}
推荐答案
classlist[n].id
classlist[n].col1
...
因为classlist [n]将是Class1的一个实例。 Intellisense应该告诉你。
Since classlist[n] will be an instance of Class1. Intellisense should show you this.
这篇关于如何将班级列表分解为各个组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!