リストを受け入れるC#のメソッドがあり、その目的はそれをSQL Serverテーブルに挿入することですが、まったく挿入されません。ここで私を助けてください。どんな洞察も非常に高く評価されています。
これが私のコードです
public void insertToDB(List<PlantillaData> plantillaDataList)
{
IsqlConnect db = new IsqlConnect();
string conQuery = db.connectionQuery;
SqlConnection con = new SqlConnection(conQuery);
try
{
con.Open();
foreach (PlantillaData plantillaData in plantillaDataList)
{
SqlCommand cmd = new SqlCommand("INSERT INTO dbo.t_employee(Telephone_Number_1," +
"Employee_Number,Employee_LastName,Employee_FirstName,Employee_MiddleName," +
"Cluster,Division,Department,Unit,Supervisor,Email,EWB_Rank,Position," +
"Location,Employee_Category)VALUES(@telNum1,@empNum,@empLastName,@empFirstName," +
"@empMiddleName,@cluster,@division,@unit,@supervisor,@email,@rank," +
"@position,@location,@emp_cat) ", con);
cmd.Parameters.Add("@telNum1", SqlDbType.VarChar).Value = plantillaData.telOneVal;
cmd.Parameters.Add("@empNum", SqlDbType.Int).Value = plantillaData.empNumVal;
cmd.Parameters.Add("@empLastName", SqlDbType.VarChar).Value = plantillaData.lName;
cmd.Parameters.Add("@empFirstName", SqlDbType.VarChar).Value = plantillaData.fName;
cmd.Parameters.Add("@empMiddleName", SqlDbType.VarChar).Value = plantillaData.mName;
cmd.Parameters.Add("@cluster", SqlDbType.VarChar).Value = plantillaData.clusterVal;
cmd.Parameters.Add("@division", SqlDbType.VarChar).Value = plantillaData.divVal;
cmd.Parameters.Add("@unit", SqlDbType.VarChar).Value = plantillaData.unitVal;
cmd.Parameters.Add("@supervisor", SqlDbType.VarChar).Value = plantillaData.supervisorVal;
cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = plantillaData.emailVal;
cmd.Parameters.Add("@rank", SqlDbType.VarChar).Value = plantillaData.rankVal;
cmd.Parameters.Add("@position", SqlDbType.VarChar).Value = plantillaData.posVal;
cmd.Parameters.Add("@location", SqlDbType.VarChar).Value = plantillaData.locVal;
cmd.Parameters.Add("@emp_cat", SqlDbType.VarChar).Value = 1;
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch
{
}
finally
{
con.Close();
}
}
}
catch (Exception e)
{
throw new Exception("SQL Error:" + e.Message.ToString());
}
finally
{
con.Close();
}
}