asp教程.net C#中怎样接受SQL 返回select受影响的行数
'实例二
OleDbCommand command = new OleDbCommand(select count(*) from biao where name="张三" ,conn);
OleDbDataReader reader = command.ExecuteReader();
if (reader.Read())
{
strValue = (string)reader.GetValue(0);
}reader.Close();
'实例二
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;
'实例三
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 = "有" + returnValue.ToString() + "条记录";
con.Close();
'最后总结一下
1、返回update、delete、insert的行数
int rows = cmd.ExecuteNonQuery();
return rows;
2、返回查询的记录数
OleDbCommand command = new OleDbCommand("select count(*) from biao where name=张三" ,conn);
OleDbDataReader reader = command.ExecuteReader();
if (reader.Read())
{
strValue = (string)reader.GetValue(0);
}
reader.Close();