這是我的SQL連接代碼。不知道我是否處理過所有錯誤。我應該使用Try Catch塊來代替使用?SQL連接代碼
using (SqlConnection con = new SqlConnection(GetSQLConnectionString()))
{
string cmdStr = "INSERT INTO table1.....";
using (SqlCommand cmd = new SqlCommand(cmdStr, con))
{
//Store parameters with values to the collection
cmd.Parameters.AddWithValue("NAME", NAME);
cmd.Parameters.AddWithValue("ID",ID);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblError.Text = ex.ToString();
}
if (con != null)
con.Close();
}
}
6個問題 - 無法接受 - 您需要接受一些過去的問題的答案 - 否則人們會更不願意幫助您。 – BonyT