Socarsky
Well-known member
- Joined
- Mar 3, 2014
- Messages
- 59
- Programming Experience
- Beginner
Here is the screenshot that proves an issue:

The thrown is mentioning this : "Specified cast is not valid."
And here is my method's code:

The thrown is mentioning this : "Specified cast is not valid."
And here is my method's code:
private Int32 MSSQLCheckQty()
{
Int32 getBalanceQty = 0;
string strConn =
"Data Source=19xxxxx;Initial Catalog=NewTBT;Persist Security Info=True;User ID=sxxx;Password=xxxx;";
string sql =
"SELECT SUM(nQty) as QTY FROM tbRecords WHERE sMPS = '" + txtMPS.Text.Trim() + "' AND sTerminalCode = '" + splitchar + "'";
using (SqlConnection conn = new SqlConnection(strConn))
{
SqlCommand cmd = new SqlCommand(sql, conn);
try
{
conn.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
//reader.Read();
while (reader.Read())
{
if (!reader.IsDBNull(reader.GetOrdinal("QTY")))
{
getBalanceQty = reader.GetInt32(reader.GetOrdinal("QTY"));
}
else
{
getBalanceQty = 0;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}