プロジェクトでコード分析を実行しています。警告が 8 件、エラーが 0 件です。それらが何を意味するのかわかりませんが、同じコード (CA2000) である 6 つと、同じコード (CA2240) である他の 2 つがあります。これは一般的な警告ですか?
Warning 1 CA2000 : Microsoft.Reliability : In method 'AdminDisplay.AdminDropDown_SelectedIndexChanged(object, EventArgs)', call System.IDisposable.Dispose on object 'ad' before all references to it are out of scope.
Warning 2 CA2000 : Microsoft.Reliability : In method 'AdminDisplay.AdminDropDown_SelectedIndexChanged(object, EventArgs)', call System.IDisposable.Dispose on object 'cmd' before all references to it are out of scope.
Warning 3 CA2000 : Microsoft.Reliability : In method 'AdminDisplay.AdminDropDown_SelectedIndexChanged(object, EventArgs)', call System.IDisposable.Dispose on object 'conn' before all references to it are out of scope.
Warning 5 CA2240 : Microsoft.Usage : Add an implementation of GetObjectData to type 'FoundationDataSet'.
Warning 7 CA2000 : Microsoft.Reliability : In method 'WebForm1.ExecuteInsert(string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string)', object 'conn' is not disposed along all exception paths.
「使用」がありますが、まだその警告が表示されます。私の構文は間違っていますか?
using (SqlConnection conn = new SqlConnection("Data Source=xx.xx.x.xx;Initial Catalog=tablenamae;User ID=xxx;Password=xxxxxxx"))
{
DataTable dt = new DataTable();
conn.Open();
SqlCommand cmd = new SqlCommand("GetStudentInfo", conn);
cmd.CommandType =CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@ID", AdminDropDown.SelectedValue));
//cmd.Connection.Open();
//cmd.ExecuteNonQuery();
SqlDataAdapter ad = new SqlDataAdapter(cmd);
ad.Fill(dt);
if (dt.Rows.Count > 0)
{
//If you want to get mutiple data from the database then you need to write a simple looping
txtFirstName.Text = dt.Rows[0]["FirstName"].ToString();
txtMiddleName.Text = dt.Rows[0]["MiddleName"].ToString();
txtLastName.Text = dt.Rows[0]["LastName"].ToString();
txtSignature.Text = dt.Rows[0]["Signature"].ToString();
}
cmd.Connection.Close();
}
これらのエラーを修正する方法についてのアイデアはありますか? ありがとう