int value2;
using (SqlConnection dataConnection = new SqlConnection(@"Data Source=MANNAN-PC\SQLEXPRESS;Initial Catalog=WareHouse;Integrated Security=True;"))
using (SqlCommand dataCommand = new SqlCommand("Select Sum(I_Quantity) from Itemswork where I_Detail='" + maskedTextBox2.Text + "' and Order_No ='" + maskedTextBox1.Text + "'", dataConnection))
{
dataConnection.Open();
value2 = Convert.ToInt32(dataCommand.ExecuteScalar());
}
값을 가져 오는 열이 이미 int
이므로 DBnull 오류가 표시됩니다. 변수의 value2
정의에서 그 값을 얻는 다른 방법이 무엇인지 알고 싶습니다. 주의 섹션 여기테이블에서 변수 값 가져 오기
에 오신 것을 환영합니다 (연결 질문에서 수정하지 예는 확인 구문). 항상 [매개 변수가있는 쿼리] (http://blog.codinghorror.com/give-me-parameterized-sql-or-give-me-death/)를 사용해야합니다. 이러한 종류의 문자열 연결은 [SQL Injection] (http://en.wikipedia.org/wiki/SQL_injection) 공격에 개방적입니다. –
쿼리 식에서 조건에 맞는 레코드를 찾을 수 없으면 ExecuteScalar가 NULL을 반환 할 수 있습니다. – Steve
오류가 _exactly_입니까? 'dataCommand.ExecuteScalar()'의 반환 값은 무엇입니까? –