How to accept the number of rows affected by SQL return select in asp.net C #

Source: Internet
Author: User

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 ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.