使用npoi将execl导入数据库报错...大神帮我看看谢谢
private void btnDR_Click(object sender, EventArgs e){
string sql = "insert into Seat (CC_LoginId, CC_LoginPassword, CC_UserName) values (@loginId,@loginPassword,@UserName)";
SqlParameter[] sp =
{
new SqlParameter("@loginId",SqlDbType.NVarChar),
new SqlParameter("@loginPassword",SqlDbType.VarChar),
new SqlParameter("@UserName",SqlDbType.NVarChar)
};
using (FileStream fs = new FileStream(@"D:\Code\20120822\ExeclDemo\bin\Debug\seat.xls", FileMode.Open, FileAccess.Read))
{
IWorkbook wk = new HSSFWorkbook(fs);
ISheet sheet = wk.GetSheet("seat");
for (int i = 0; i <= sheet.LastRowNum; i++)
{
IRow row = sheet.GetRow(i);
for (int c = 1; c < row.LastCellNum; c++)
{
ICell cell =row.GetCell(c);
sp[c-1].Value=cell.ToString();
}
SqlHelper.SqlHelper.ExecuteNonQuery(sql,CommandType.Text,sp);
}
}
MessageBox.Show("OK");
}
使用的是SQLHelper ...
public static int ExecuteNonQuery(string sql, CommandType type,params SqlParameter[] parameters)
{
using (SqlConnection conn = new SqlConnection(con))
{
if(conn.State == System.Data.ConnectionState.Closed)
{
conn.Open();
}
using (SqlCommand cmd = conn.CreateCommand())
{
= sql;
= type;
if (parameters != null && parameters.Length > 0)
{
cmd.Parameters.AddRange(parameters);
}
cmd.Parameters.Clear();
return cmd.ExecuteNonQuery();报错是...另一个SqlParameterCollection中已包含SqlParameter。
}
}
}