在.NET中调用存储过程
2007-05-10 13:37
295 查看
今天试了一下用存储过程取得数据。归纳方法如下:
1.用SqlCommand和DataSet:
SqlConnection conn=new SqlConnection("server=(local);uid=;password=;database=");
SqlCommand cmd=new SqlCommand("StoreProcedure",connn);
cmd.CommandType=CommandType.StoreProcedure;
SqlDataAdapter dsCommand=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
dsCommand.Fill(ds);
2.
用SqlCommand和SqlDataReader
不带参数:
Sqlconnection conn=new SqlConnection("server=(local);uid=;password=;database=");
SqlCommand cmd=new SqlCommand("StoreProcedure",conn);
cmd.CommandType=CommandType.StoreProcedure;
SqlDataReader dr=cmd.ExecuteReader()
while(dr.Read())
{
Response.Write(dr.Item["Field"]);
}
带输入参数:
Sqlconnection conn=new SqlConnection("server=(local);uid=;password=;database=");
SqlCommand cmd=new SqlCommand("StoreProcedure",conn);
cmd.CommandType=CommandType.StoreProcedure;
param=command.Parameters.Add("@inputText",SqlDbType.Int);
param.Value=inputValue;
SqlDataReader dr=cmd.ExecuteReader()
while(dr.Read())
{
}
conn.Close()
带输出参数:
Sqlconnection conn=new SqlConnection("server=(local);uid=;password=;database=");
SqlCommand cmd=new SqlCommand("StoreProcedure",conn);
cmd.CommandType=CommandType.StoreProcedure;
param=command.Parameters.Add("@outText",SqlDbType.Int);
param.Direction=ParameterDirection.Output;
SqlDataReader dr=cmd.ExecuteReader()
while(dr.Read())
{
}
outValue=command.Parameters["@outText"].Value;
conn.Close()
1.用SqlCommand和DataSet:
SqlConnection conn=new SqlConnection("server=(local);uid=;password=;database=");
SqlCommand cmd=new SqlCommand("StoreProcedure",connn);
cmd.CommandType=CommandType.StoreProcedure;
SqlDataAdapter dsCommand=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
dsCommand.Fill(ds);
2.
用SqlCommand和SqlDataReader
不带参数:
Sqlconnection conn=new SqlConnection("server=(local);uid=;password=;database=");
SqlCommand cmd=new SqlCommand("StoreProcedure",conn);
cmd.CommandType=CommandType.StoreProcedure;
SqlDataReader dr=cmd.ExecuteReader()
while(dr.Read())
{
Response.Write(dr.Item["Field"]);
}
带输入参数:
Sqlconnection conn=new SqlConnection("server=(local);uid=;password=;database=");
SqlCommand cmd=new SqlCommand("StoreProcedure",conn);
cmd.CommandType=CommandType.StoreProcedure;
param=command.Parameters.Add("@inputText",SqlDbType.Int);
param.Value=inputValue;
SqlDataReader dr=cmd.ExecuteReader()
while(dr.Read())
{
}
conn.Close()
带输出参数:
Sqlconnection conn=new SqlConnection("server=(local);uid=;password=;database=");
SqlCommand cmd=new SqlCommand("StoreProcedure",conn);
cmd.CommandType=CommandType.StoreProcedure;
param=command.Parameters.Add("@outText",SqlDbType.Int);
param.Direction=ParameterDirection.Output;
SqlDataReader dr=cmd.ExecuteReader()
while(dr.Read())
{
}
outValue=command.Parameters["@outText"].Value;
conn.Close()
相关文章推荐
- 步步为营VS 2008 + .NET 3.5(10) - DLINQ(LINQ to SQL)之调用存储过程的添加、查询、更新和删除
- .NET中统一的存储过程调用方法(收藏)
- 在.NET中调用Oracle9i存储过程经验总结
- .NET中统一的存储过程调用方法(收藏)
- .net 调用Oracle存储过程
- .net调用存储过程详细介绍
- 在.net中如何把调用存储过程代码写入数据连接层中
- 在.NET中调用Oracle9i存储过程经验总结
- 在.NET中调用Oracle9i存储过程经验总结
- .NET中统一的存储过程调用方法
- 步步为营VS 2008 + .NET 3.5(10) - DLINQ(LINQ to SQL)之调用存储过程的添加、查询、更新和删除
- 在.NET中调用Oracle9i存储过程经验总结------------转载
- 在.NET中调用Oracle9i存储过程经验总结
- 在.NET中调用Oracle9i存储过程经验总结
- .net,调用sql存储过程
- 我转载的文章《.NET中统一的存储过程调用方法 》具体实现代码
- .NET中统一的存储过程调用方法(收藏)
- 在.NET中调用Oracle9i存储过程经验总结
- ORACLE通用分页存储过程及.NET调用方式
- 10、步步为营VS 2008 + .NET 3.5(10) - DLINQ(LINQ to SQL)之调用存储过程的添加、查询、更新和删除