I am applying the following query to get the value of an existing field in a table and capture it in a variable.
var captbarras = TextBoxLeerSerial.Text;
string sqli = "SELECT codigobarras from articulo WHERE codigobarras='captbarras'";
var obtenerarticulos = db.Database.SqlQuery<string>(sqli).FirstOrDefault();
if (obtenerarticulos == TextBoxLeerSerial.Text)
{
ScriptManager.RegisterStartupScript(this, this.GetType(),
"alert",
"alert('No se ha podido actualizar el codigo de barras, este codigo ya se utiliza');window.location ='/Aspx/Compras/CargarSeriales.aspx';",
true);
}
What I need to do is get the value that exists in the field I select and get it in the variable obtenerarticulos
my big drawback is that I do not capture any value and the value I enter in the textbox TextBoxLeerSerial
if it exists.
The data type of the codigobarras
field in the DB is varchar
and in case that value does not exist, apply for the else ...