C# 遍历两个一维数组,并与数据库中的列表名称匹对,并将对应的比配结果添加到对应的列下:
两个一维数组分别是:
string[] Alps = new string[L]; //对应字母
string[] nums = new string[L]; //数值
遍历表中的列名与Alps[L]进行匹配,然后将nums[L]中的值加入到对应的列表名后。
例如 ,遍历 Alps[0] = A , 将 nums[0] = 32 添加到 A 列下。
大概是这么个意思,求大神给一个demo.
目前此部分功能代码:
private void button3_Click(object sender, EventArgs e)
{
string[] Alps = new string[L];
string[] nums = new string[L];
// 逐行读取文本,并将字母和对应的数值存入到数组中
for (int i = 0; i < L; i++) //for 循环行
{
string[] Array = richTextBox1.Lines[i].Split('='); // 以“=”一行一行进行分割
Alps[i] = Array[0].Trim().ToUpper().Replace(" ", ""); // 将获取的字母全部大写存放到alps[]中
nums[i] = Array[1].Trim().Replace(" ", ""); // 将获取的数值存放到nums[]中
}
string SqlStr = string.Format("insert into 曲柄轴({0})values({1})", string.Join(",", Alps), string.Join(",", Alps.Select(item => "@" + item)));
using (SqlConnection con = new SqlConnection(Constr))
{
SqlCommand cmd = new SqlCommand(SqlStr, con);
for (int i = 0; i < L; i++)
{
cmd.Parameters.AddWithValue("@" + Alps[i], nums[i]);
}
con.Open();
int result = cmd.ExecuteNonQuery();
}
}