最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net C#中怎样接受SQL 返回select受影响的行数
时间:2010-05-21 编辑:简简单单 来源:一聚教程网
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();
-
上一个: asp.net 程序IIS自动部署问题
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10