I'm trying to read QuaInMagazine
(int
value) from a SQL Server database. This is part of code:
sqlCon.Open();
using (SqlCommand sqlComm = new SqlCommand("Select QuaInMagazine from tbl_Parts2 where Name = '" + Name_txt.Text + "' and Number='" + Number_txt.Text + "'", sqlCon))
{
using (SqlDataReader reader = sqlComm.ExecuteReader())
{
qua = (int)reader["QuaInMagazine"];
}
}
qua = qua + Convert.ToInt32(Qua_txt.Text);
sqlCon.Close();
When I run it, I get an InvalidOperationException
error at this instruction:
qua = (int)reader["QuaInMagazine"];
The error says that there wasn't any data. Any ideas what I'm doing wrong?