怎样在C#中运用存储过程向数据库进行修改添加
解决方案 »
- 求一个代码(分页)
- 如何用代码加入控件
- 动态无刷新展示被嵌套的datagrid的细节
- iframe的打印问题
- 谁能帮我解释下这句代码是什么意思?
- 现在微软准备统一PC,平板,手机系统了。请问...
- 新手上路!简单控件问题!在线等待!
- 我已经用通过引用两个DataSet生成了Crystal Reports,请问如何填充报表
- WPF 8k 的分辨率下 渲染的问题
- 利用栈的基本操作实现将任意一个十进制整数转化为二进制和八进制整数(我是用新学的c#写的,但是运行结果老是不对,试了多次也找不到问题,求大佬相助)
- 通过编辑DataGridView更改SQL2000数据库
- 求教一个算法:穷举法生成{1,2…,n}的全排列
{
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("lt_query", GetConn());
sda.SelectCommand = cmd;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@querytype", System.Data.SqlDbType.Int).Value = querytype;
cmd.Parameters.Add("@selecttext", System.Data.SqlDbType.NVarChar, 4000).Value = selecttext;
DataSet ds = new DataSet();
sda.Fill(ds);
GetConn().Close();
}SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GOALTER proc lt_inoutquery
(
@querytype int,
@selecttext nvarchar(4000)
)
as
declare @selectsql nvarchar(4000)--最终查询语句
if(@querytype=1)--历史记录查询
begin
set @selectsql=@selecttext
exec (@selectsql)
end
else if(@querytype=2)--同批次查询
begin
set @selectsql=@selecttext
exec (@selectsql)
end
else if(@querytype=3)
begin
set @selectsql=@selecttext
exec (@selectsql)
endGO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
{
SqlCommand cmd=new SqlCommand("proc_Insert",con);
cmd.CommandType=CommandType.StoredProcedure;
SqlParameter s1=new SqlParameter("@name",SqlDbType.VarChar,20);
parProvinceID.Value="";
cmd.Parameters.Add(s1);
con.Open();
int result=cmd.ExecuteNonQuery();
con.Close();
if(result>0)
{
return true;
}
else
{
return false;
}
}
create proc proc_Insert
@name VARCHAR(20)
AS
DECLARE @sql varchar(200)
set @sql=' insert into Tb(name) values('+@name+')'
exec @sql
可看看sqlhelper或51aspx.com里看看,操作实例很多