My problem is this:
I have a connection with a data base sql server 2008
which extracts a number (manufacturing order) only if that number is in the database, if the number is not found send me a Messagebox
where it indicates that the number is invalid. the code runs well, when I digit a number that if it is in the database it does what I need and when the number is not in the database it tells me that the number is not valid but only if I entry less than 8 characters, if I digit 9 or more the code does not compile and shows me an error in - > if (reader1.Read() == false)
.
this is my code ...
class formclass
{
SqlConnection con = new SqlConnection();
public string ordr ;
public string prt ;
public string limpio()
{
// limpiar el estring que se escanea para hacer procesos de busqueda
ordr = Regex.Replace(ordr, @"^~200\|(.*)~$", "$1");
//conectar con la base de datos para verificar si existe el manufacturing order id
SqlConnection con = new SqlConnection("Data Source=misdatabase;Integrated Security=true;");
con.Open();
SqlCommand co = new SqlCommand("SELECT mfgOrder.ManufacturingOrderId FROM ShopFloorControl.ManufacturingOrder_base mfgOrder WHERE mfgOrder.ManufacturingOrderId = '" + ordr + "'", con);
using (SqlDataReader reader1 = co.ExecuteReader())
{
if (co != null)
{
if (reader1.Read() == false)
{
MessageBox.Show("Manufacturing Order invalid or empty", "", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
con.Close();
}
return ordr;
}
If someone can help me, thank you.