-4
string conStr = null;
SqlCommand cmd;
SqlConnection cnn;
string sql = null;
conStr = "Data Source=DELL-PC\\SQLEXPRESS;Initial Catalog=DBMSI;Integrated Security=True";
sql = "insert into CEC_Employee values('"+empid + "','" + name + "','" + fname + "','" + mname + "','" + lname + "','" + address + "','" + postcode + "','" + job + "','" + sdate + "','" + whours + "','" + sph + "','" + spa + "','" + location + "','" + working + "','" + gender + "','" + dob + "','" + pn + "','" + exp + "','" + vtype + "','" + vexp + "','" + qualification + "','" + email + "','" + number + "','" + nin + "','" + sort + "','" + acc + "','" + bank + "','" + nname + "','" + rel + "','" + addkin + "','" + cnokin + "','" + emailkin + "')";
cnn = new SqlConnection(conStr);
try
{
cnn.Open();
cnn = new SqlConnection(conStr);
cmd = new SqlCommand(sql, cnn);
cmd.ExecuteNonQuery();
cmd.Dispose();
cnn.Open();
MessageBox.Show("Employee Details registered Succesffuly");
// Keeps on moving to the Exception part of the code. Doesn't execute the try portion of the program.
}
catch (Exception ex)
{
MessageBox.Show("Error Occoured - Employee Details were not recorded");
}
在線找到該代碼。請幫助使其工作。謝謝!代碼不起作用。 C#執行非查詢
請花點時間仔細閱讀此* *:[Ask] – Plutonix 2015-04-03 18:43:27
嘗試查看'ex.Message'並查看內容。它會給你更多關於錯誤的信息。 – 2015-04-03 18:43:58
什麼是異常消息和堆棧跟蹤?你自己做了什麼才能使它工作?它期望一個帶有表格的數據庫,根據連接字符串中的任何內容進行配置 - 您是否具有本地的所有設置? – 2015-04-03 18:44:02