我正在尝试根据我的要求插入以插入以下数据。例如:我的excel表是这样的:
id name codes
1 a 12
2 b 13,14,15
3 c 16-19
我的要求是这样的:
id name codes
1 a 12
2 b 13
2 b 14
2 b 15
3 c 16
3 c 17
3 c 18
3 c 19
我正在使用 c#。任何人都可以帮助我.... thnx 提前。
我的代码:
for (rCnt = 2; rCnt <= range.Rows.Count; rCnt++)
{
cmd = "insert into " + tablename + " values (";
effective_date = VerifyDateTime(range.Cells[rCnt, 7].Value);
destination = (string)(range.Cells[rCnt, 1] as Excel.Range).Value2;
prefix = range.Cells[rCnt, 3].Value.ToString();
codes = range.Cells[rCnt, 2].Value.ToString();
level = range.Cells[rCnt, 5].Value.ToString();
rate = range.Cells[rCnt, 4].Value.ToString();
change = range.Cells[rCnt, 6].Value.ToString();
company_id = cmbcompanyid.SelectedItem.ToString();
string s = range.Cells[rCnt, 6].Value.ToString();
List<string> l = new List<string>(s.Split(';', '-'));
int le = 0;
for (le = 0; le <= l.Count; le++)
{
change = l[le];
cmd = cmd + "'" + destination + "','" + codes + "','" + prefix + "','" + rate + "','" + level + "','" + change + "','" + effective_date + "','" + company_id + "')";
// cmd = cmd + "'" + destination + "','" + codes + "','" + prefix + "','" + rate + "','" + level + "','" + change + "','" + effective_date + "','" + company_id + "')";
cmd = ReplaceSpecialCharacters(cmd);
MySqlCommand sqlCmd = new MySqlCommand(cmd, sqlCon);
var i = sqlCmd.ExecuteNonQuery();
}
}