ASP tutorial How to accept SQL return a select affected number of rows in. NET C #
' Instance two
OleDbCommand command = new OleDbCommand (select COUNT (*) from Biao where Name= "John", Conn);
OleDbDataReader reader = command. ExecuteReader ();
if (reader. Read ())
{
strvalue = (string) reader. GetValue (0);
}
Reader. Close ();
' Instance two
public static DataSet Query (string sqlstring)
{
using (SqlConnection connection = new SqlConnection (connectionString))
{
DataSet ds = new DataSet ();
Try
{
Connection. Open ();
SqlDataAdapter command = new SqlDataAdapter (SqlString, connection);
Command. Fill (ds, "DS");
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception (ex. message);
}
return DS;
}
}
DataSet ds = new DataSet ();
ds = Query ("SELECT * from Tbname");
int count = ds. Tables[0]. Rows.Count;
' Instance three
SqlConnection con = new SqlConnection ();
SqlCommand cmd = con. CreateCommand ();
Cmd.commandtext = "SELECT count (1) from Stockout";
Con. ConnectionString = "server=10.10.66.232;database=uerp;uid=uerp;pwd=uerp5678";
Con. Open ();
int returnvalue = (int) cmd. ExecuteScalar ();
Label3.text = "have" + returnvalue.tostring () + "record";
Con. Close ();
' Finally, sum up
1. Returns the number of rows for update, delete, insert
int rows = cmd. ExecuteNonQuery ();
return rows;
2, return the number of records of the query
OleDbCommand command = new OleDbCommand ("SELECT count (*) from Biao where Name= John", Conn);
OleDbDataReader reader = command. ExecuteReader ();
if (reader. Read ())
{
strvalue = (string) reader. GetValue (0);
}
Reader. Close ();