ADO Performance
home
DataReader
Reader DT+Load
Next Result
ExecuteScalar
Dataset X Scalar
Table Mapping
EXECUTE Scalar - Nothing is faster than Scalar
Product ID:
Remember: ExecuteScalar request only
One Column
and
One Row
Show code / exibir código
using System.Data.SqlClient;
using System.Web.Configuration;
string myConnection = WebConfigurationManager.ConnectionStrings["ConnStringKey"].ConnectionString;
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
string sql = "Select UnitsInstock FROM Products Where ProductID=@productID";
DBGeneric objDB = new DBGeneric();
lbSearch.Text = string.Format("Qty is {0:n0}", Convert.ToDecimal(objDB.GenericScalar(sql, txtID.Text.Trim())));
}
catch (Exception ex)
{ Response.Write(ex.Message); }
}