내 프로젝트에서 코드 분석을 실행하고 있습니다. 나는 8 개의 경고와 0 개의 오류를 얻고있다. 나는 그들이 의미하는 바를 모르지만 6 개는 동일한 코드 (CA2000)이고 다른 2 개는 동일한 코드 (CA2240)입니다. 이것은 일반적인 경고입니까?VS2010의 프로젝트에서 코드 분석 실행
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();
}
이러한 오류를 수정하는 방법에 대한 아이디어가 있으십니까? 감사합니다.
1 만 user'는 감사 돌아 오지 않을 이유'궁금 당신을 도와주세요. – jp2code