C#按钮执行SQL存储过程 80C

存储过程名字:p_vdp_vendor_jk

执行的存储过程语句:EXEC p_vdp_vendor_jk'90029','02','2017-05-22 10:57:03.513'

语句解释:90029-学生代码 02-无需更改 2017-05-22-需要定到每个月的22日

10:57:03.513 无需更改

现需要在C#窗体程序中执行该存储过程,自动将时间更改为每个月22日,学生代码需要手动填写在textbox中。执行后需要将返回值显示在DataGridView中。

烦请大神指点!

2

4个回答

 // SqlServerHelper.ConnectionString  是我在代码中定义的链接串,用的时候替换成自己对应的连接串即可<br>using (SqlConnection connection = new SqlConnection(SqlServerHelper.ConnectionString))
            {
                connection.Open();         
                SqlCommand cmd = new SqlCommand("存储过程名", connection);
                cmd.Parameters.Add("@param1", SqlDbType.Int);
                cmd.Parameters["@param1"].Value = "param1_value";
                cmd.Parameters["@param1"].Direction = ParameterDirection.Input;
                cmd.Parameters.Add("@param2", SqlDbType.Int);
                cmd.Parameters["@param2"].Value = "param2_value";
                cmd.Parameters["@param2"].Direction = ParameterDirection.Input;//Outpu

                cmd.Connection = connection;
                cmd.CommandType = CommandType.StoredProcedure;//这里标识调用类型
                SqlDataReader dr = cmd.ExecuteReader(); //执行SQL语句,返回结果集合
          //int rerows = cmd.ExecuteNonQuery();//执行SQL语句,受影响的行数
                while (dr.Read())
                {
                    //返回结果处理
                    //dr[0],dr["col_name"]
                }
                dr.Close(); //关闭执行
                connection.Close(); //关闭数据库
            }
3
qq_32393069
qq_32393069 回复苏小喵: 大神,请问如何让修改
一年多之前 回复
devmiao
见了你女王大人喵姐还不跪下 回复qq_32393069: 字段类型要修改下。
一年多之前 回复
qq_32393069
qq_32393069 System.FormatException”类型的未经处理的异常在 System.Data.dll 中发生 其他信息: 将参数值从 String 转换到 Int32 失败。就是在转换日期的时候出现的错误
一年多之前 回复
hxycsdn9159
hxycsdn9159 回复qq_32393069: 你报的错误很明显了,你把你SqlServerHelper类里面的ConnectionString这个字段这样声明就行了:public static string ConnectionString ="/*你真正的数据库连接串*/"
一年多之前 回复
qq_32393069
qq_32393069 大神您好,我这调试的过程中报了 严重性 代码 说明 项目 文件 行 禁止显示状态 错误 CS0122 'SqlSerberHelper.ConnectionString' is inaccessible due to its protection level fd C:\TOOLS\fd\fd\Form1.cs 这个错误,但是我不知道如何将private 转换为Public。请大神指点
一年多之前 回复

Dim arParms() As SqlParameter = New SqlParameter(2) {}

    arParms(0) = New SqlParameter("@code", SqlDbType.NVarChar, 50)
    arParms(0).Value = textbox1.text

    arParms(1) = New SqlParameter("@notChange", SqlDbType.NVarChar, 10)
    arParms(1).Value = "02"

    arParms(2) = New SqlParameter("@NeedDate", SqlDbType.NVarChar, 200)
    arParms(2).Value = now.year & "-" & now.month & "-22 10:57:03.513"

    Dim ds As DataSet = SqlHelper.ExecuteDataSet(conn, CommandType.StoredProcedure, "p_vdp_vendor_jk", arParms)

            vb 代码,相信很容易能转成C#,sqlhelper 从网上找
0

存储过程都写了,前端代码不会写吗

0

public class DataHelper
{
private string connString = null;
public DataHelper(string conStr)
{
this.connString = conStr;
}
///
/// 执行存储过程
///
/// 执行存储过程的属性
/// ProcName 存储过程的名称
/// MethodName 执行SqlCommand 方法的名称
/// PrmList 存储过程的参数
///
/// 返回执行的结果
public object ExecProcRetObj(ExeProc ep)
{
if (this.connString != null && this.connString != string.Empty)
{
try
{
SqlConnection con = new SqlConnection(this.connString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Exec " + ep.ProcName + " ";
foreach (object obj in ep.PrmValue)
{
cmd.CommandText += obj + ",";
}
cmd.CommandText = cmd.CommandText.Remove(cmd.CommandText.Length - 1, 1);
Type ty = cmd.GetType();
con.Open();

                //用反射根据输入的方法名 执行对应的方法 
                object retObj = ty.InvokeMember(ep.MethodName, BindingFlags.InvokeMethod, null, cmd, null);
                if (retObj.GetType().FullName == "System.Data.SqlClient.SqlDataReader")
                {
                    //将返回的object 转换成DataTable 
                    DataTable retDt = new DataTable();
                    retDt.Load(retObj as SqlDataReader);
                    con.Close();
                    con.Dispose();
                    return retDt;
                }
                return retObj;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("获取数据发生错误\n" + ex.Message);
            }
        }
        return null;
    }
}
-2
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
c#之执行SQL存储过程
目的:通过C#.NET调用SQL Server数据库中定义的存储过程。 示例一: 存储过程名:sp_login 输入参数1:@username nvarchar(50) 输入参数2:@password nvarchar(50) 输出参数:@nickname nvarchar(50) 返回值:@retval int using (SqlConnection sqlConn = new
C#执行SQL存储过程返回表
参考参考:/* 创建一个名为Get的储存过程先定义两个参数 ,其中@count为输出参数sql语句中 第一句返回该表所有内容, 第二句 返回表的行数,并把值赋给输出参数*/CREATE PROCEDURE [Get] @name varchar (50), @count int output ASSELECT * FROM Table1 SELECT @count=COUNT(*) FROM Ta
执行SQL存储过程实例
执行SQL存储过程实例 privatevoidtoolStripButton3_Click(objectsender,EventArgse){连接数据库#region连接数据库并执行存储过程proSqlConnectionscc=newSqlConnecti...
SQL存储过程执行出错~~
declare @begindate varchar(10)rnset @begindate='2007-05-01'rnrndelete yj where convert(char(7),yjdate,120)=left(@begindate,7)rn--复制上月月结数据rninsert into yj(yjdate,bomid,qty_a_l,amount_a_l,in_qtys,amount_m,out_qtys,aunitprice,amount_o,rnqty_a,amount_a)rnselect @begindate,bomid,qty_a,amount_a,in_qtys,amount_m,out_qtys,aunitprice,amount_o,rnqty_a,amount_a from yj where convert(char(7),yjdate,120)=rnleft(convert(char(7),dateadd(month,-1,convert(datetime,@begindate,120)),120),7)rn--对COPY的数据进行修改rn--更新 入,出库数,入库金额rnupdate yj set in_qtys=b.in_qty,out_qtys=b.out_qty,amount_m=b.amount_m rnfrom yj inner join (rnselect bomid,isnull(sum(in_qty),0) in_qty,rnisnull(sum(amount),0) amount_m,isnull(sum(out_qty),0) out_qty rnfrom delivery_view where convert(char(7),datetime,120)=left(@begindate,7) group by bomid ) b rnon yj.bomid=b.bomidrnwhere convert(char(7),yj.yjdate,120)=left(@begindate,7)rnrnrn--当上月结存数为0(即本月期初数为0)并且本月入库也为0时,平均单价为0rnupdate yj set aunitprice=0, --平均单价rnamount_o=out_qtys*0, --本月出库金额 rnqty_a=qty_a_l+in_qtys-out_qtys, --结存数rnamount_a=amount_a_l+amount_m-(out_qtys*0), --结存金额rnwhere yj.qty_a_l=0 and yj.in_qtys=0 and convert(char(7),yjdate,120)=left(@begindate,7)rnrn--当上月结存数不为(即本月期初数量不为0)0或本月入库数不为0时rn--这一段出错,提示:rn服务器: 消息 8134,级别 16,状态 1,行 31rnDivide by zero error encountered.rnThe statement has been terminated.rn被0除.可是这个我已经把为0的记录去除了.而且我把它COPY到一个新查询中运行是没问题的.很奇怪!!rnupdate yj set aunitprice=(amount_a_l+amount_m)/(qty_a_l+in_qtys), --平均单价rnamount_o=out_qtys*convert(numeric(18,2),(amount_a_l+amount_m)/(qty_a_l+in_qtys)), --本月出库金额rnqty_a=qty_a_l+in_qtys-out_qtys, --结存数rnamount_a=amount_a_l+amount_m-rn(out_qtys*convert(numeric(18,2),(amount_a_l+amount_m)/(qty_a_l+in_qtys))) --结存金额rnwhere (qty_a_l<>0 or in_qtys>0) and convert(char(7),yjdate,120)=left(@begindate,7)rnrn--上月月结中的物料在本月无出入记录rnupdate yj set in_qtys=0,amount_m=0,out_qtys=0,rnaunitprice=0, --平均单价rnamount_o=0, --本月出库金额rnqty_a=qty_a_l, --结存数rnamount_a=amount_a_l --结存金额rnwhere convert(char(7),yjdate,120)=rnleft(@begindate,7) and yj.bomid not in rn(rnselect bomid from delivery_view where convert(char(7),datetime,120)=convert(char(7),@begindate,120)rn)rnrn----处理yj中不存在的物料-----rn--当入库数据量>0时rninsert into yj(yjdate,bomid,qty_a_l,amount_a_l,in_qtys,amount_m,out_qtys,aunitprice,amount_o,rnqty_a,amount_a)rnselect convert(datetime,@begindate,120),bomid,0 qty_a_l,0 amount_a_l,rnsum(in_qty) in_qty,sum(amount) amount,sum(out_qty) out_qty,rnconvert(numeric(18,2),sum(amount)/sum(in_qty)) aunitprice, --平均单价rnsum(out_qty)*convert(numeric(18,2),sum(amount)/sum(in_qty)) as amount_o,rnsum(in_qty)-sum(out_qty) qty_a,rnsum(amount)-sum(out_qty)*convert(numeric(18,2),sum(amount)/sum(in_qty)) amount_arnfrom (rnselect * from delivery_view where bomid not in rn( select bomid from yj where convert(char(7),yjdate,120)=convert(char(7),@begindate,120))rnand convert(char(7),datetime,120)=convert(char(7),@begindate,120)rn) arngroup by bomidrnhaving sum(in_qty)>0rnrn--当入库数量=0时,平均单价按0计算rninsert into yj(yjdate,bomid,qty_a_l,amount_a_l,in_qtys,amount_m,out_qtys,aunitprice,amount_o,rnqty_a,amount_a)rnselect convert(datetime,@begindate,120),bomid,0 qty_a_l,0 amount_a_l,rnsum(in_qty) in_qty,sum(amount) amount,rnsum(out_qty) out_qty,0 aunitprice, --平均单价rnsum(out_qty)*0 as amount_o,rnsum(in_qty)-sum(out_qty) qty_a,rnsum(amount)-sum(out_qty)*0 amount_arnfrom (rnselect * from delivery_view where bomid not in rn( select bomid from yj where convert(char(7),yjdate,120)=convert(char(7),@begindate,120) ) rnand convert(char(7),datetime,120)=convert(char(7),@begindate,120)rn) arngroup by bomidrnhaving sum(in_qty)=0
PB 执行SQL存储过程的问题
PB12.5rnSQL 2008 R2rn这是存储过程rn[code=csharp]rnalter procedure dbo.sp_insertchaxun_ls rnasrnbeginrn--更新本地rndeclare @a nvarchar(max)rnselect @a='192.168.1.125'rnExecute ('insert into chaxun_ls select distinct a.* from'+ '['+@a+']' + '.jmg.dbo.chaxun a,chaxun b where a.flag>b.flag')rn--更新服务器rnExecute ('insert into '+ '['+@a+']' + '.jmg.dbo.chaxun_ls select distinct a.* from'+ '['+@a+']' + '.jmg.dbo.chaxun a,chaxun b where a.flag
sql存储过程执行问题。(急)
写一个存储过程,接受四个变量,然后执行多条语句有update,insert等,均用到变量。现出现,单步执行和通过打开执行均可正确完成。但通过exec执行,输入变量后,出现后面多条update语句更新结果出现问题,好像并未执行一样。请问这是为什么?rn部份过程如下;rnrnALTER proc zb_importdata_vol1rn@dep varchar(5), --部门rn@store varchar(6), --仓库号rn@begin_date varchar(15)='1990-01-01', --起始日期rn@end_date varchar(15)='2999-01-01' --终止日期rnrnasrnrn--清除临时表数据rn if exists(select * from balance_temp_1)rn delete from balance_temp_1rnrn--清除cte_balance_temp表中查询部门与仓库对应的数据rndelete from cte_balance_temp rnwhere dept_id=@dep and store_no=@storernrn--插入本月接受料件数量rnrn--1.导入581数据到exp_581表中rn exec p_exp_581 @dep,@store,@begin_date,@end_daternrn--2.从exp_581表中插入数据到cte_balance_temprn update cte_balance_temprn set img_qty=[581_qty],store_no=t2.store_norn from (rn select g_no,dept_id,store_no,sum(cm_qty) as [581_qty]rn from exp_581rn group by g_no,dept_id,store_no) t2rn inner join cte_balance_temp t1rn on t1.g_no=t2.g_no andrn t1.dept_id=t2.dept_idrn where t1.store_no='t1'rnrn......rn--插入本月放弃品数量rn update cte_balance_temprn set aba_qty=quantity,store_no=t2.storage_norn from (rn select cop_g_no,dept,storage_no, sum(amount) as quantity rn from T_SCB_BACK rn where type='1'and class='1'and isbreakup in ('0','2')rn and storage_date between @begin_date and @end_datern and dept=@deprn and storage_no=@storern group by cop_g_no,dept,storage_no) t2rn inner join cte_balance_temp t1rn on t1.g_no=t2.cop_g_no andrn t1.dept_id=t2.deptrn where t1.store_no=@store or t1.store_no='t1'rnrn--插入本月在线品数量 (下面的语句拿出来单步执行没问题,但exec就显示更新数为0) rn update cte_balance_temprn set online_qty=quantity,store_no=t2.storage_norn from (rn select cop_g_no,dept,storage_no, sum(amount) as quantity rn from T_SCB_BACK rn where type='1'and class='3'and isbreakup in ('0','2')rn and storage_date=@end_datern and dept=@deprn and storage_no=@storern group by cop_g_no,dept,storage_no) t2rn inner join cte_balance_temp t1rn on t1.g_no=t2.cop_g_no andrn t1.dept_id=t2.deptrn where t1.store_no=@store or t1.store_no='t1'rn.......
PL SQL存储过程执行问题
刚接触ORACLE,,问个很菜鸟的问题,谢谢大家了。。。rnrncreate or replace procedure SPA Isrnbeginrn rnDELETE FROM NAME;rnrnINSERT INTO NAME VALUE(A,B,C,D)rnSELECT A,B,C,D FROM NAME2;rnrnend SPA;rnrn按F8提示编译成功。怎么能像SQL SERVER里一样执行出结果集啊rn还有就是在SQL窗口中执行 EXEC SPA; 报错:SQL语句无效rnrn但是将语句直接拿出来再SQL窗口中执行又是成功的。。rnrn郁闷中。。
sql存储过程动态执行sql
1.动态执行sqlcreate proc proc_GetWorkHourByEmpId@key1 varchar(100), --关键字@user_group1 varchar(100),--用户分组as begindeclare @SqlSelect nvarchar(2000),@ParmDefinition nvarchar(max);set @SqlSelect=' select * ...
定时自动执行SQL存储过程
定时执行
ado.net 执行sql存储过程
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; p...
C# 一个按钮执行另一个按钮的代码
比方 第一个按钮 protected void Button1_Click(object sender, EventArgs e) { //?????????? } 第二个按钮 protected void Button2_Click(object sender, EventArgs e) { Button1_Click(sender,e); }第二个就能使用第一个按钮的代码 ==========...
SQL存储过程SQL存储过程SQL存储过程
存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程
执行SQL存储过程对应数据类型的问题
asp程序中执行一个添加记录到数据库的存储过程,执行时出错:rnMicrosoft OLE DB Provider for SQL Server 错误 '80004005' rnrn精度无效。rnrnasp程序中是这样写的rnoCmd.Parameters.Append oCmd.CreateParameter("@sName",adVarWChar,adParamInput,50,sPart)rnoCmd.Parameters.Append oCmd.CreateParameter("@sBrand",adSmallInt,adParamInput,2,sBrand)rnoCmd.Parameters.Append oCmd.CreateParameter("@sTempe",adVarChar,adParamInput,50,sTemperature)rnoCmd.Parameters.Append oCmd.CreateParameter("@sDescr",adVarWChar,adParamInput,150,sDescr)rnoCmd.Parameters.Append oCmd.CreateParameter("@sFileName",adVarChar,adParamInput,50,sFileName)rnoCmd.Parameters.Append oCmd.CreateParameter("@sFileSize",adNumeric,adParamInput,9,sFileSize)rnoCmd.Parameters.Append oCmd.CreateParameter("@sPages",adUnsignedTinyInt,adParamInput,1,sPages)rnrn对应的存储过程的数据类型如下:rn @sName nvarchar(50),rn @sBrand smallint,rn @sTemp varchar(50) = null,rn @sDescr nvarchar(150) = null,rn @sFileName varchar(50) = null,rn @sFileSize decimal = null,rn @sPages tinyint = null rn请问是那个数据类型写错了呢?
ADO中执行SQL存储过程的问题
请问各位大侠,ADO中执蠸QL的存储过程应该如何做,小弟试过如下方法:rn1。MyCommandPtr->ActiveConnection=MyConnectedPtr;rn MyCommandPtr->CommandText="USE pubs GO hhggxx.Create_Table GO";rn MyRecordsetPtr->PutRefSource(MyCommandPtr);rn2。MyCommandPtr->CommandText="USE pubs";rn MyRecordsetPtr->PutRefSource(MyCommandPtr);rn MyCommandPtr->CommandText="GO";rn MyRecordsetPtr->PutRefSource(MyCommandPtr);rn MyCommandPtr->CommandText="hhggxx.Create_Table";rn MyRecordsetPtr->PutRefSource(MyCommandPtr);rn MyCommandPtr->CommandText="GO";rn MyRecordsetPtr->PutRefSource(MyCommandPtr);rn3. MyConnectedPtr->Execute("USE pubs GO hhggxx.Create_Table GO",rn NULL,adCmdStoredProc);rn 但是都没有成功,数据库里面没有hhggxx.Create_Table存储过程所要求建立的表
SQL存储过程学习asp.net ,c#
SQL存储过程学习SQL存储过程学习SQL存储过程学习
sql存储过程怎么执行不同操作
我想在同一个存储过程执行增删改查,该怎么做啊,谁可以给个例子看看啊rnrn我这样写 对不对啊,会存储过程的帮我看下啊,我想实现的是一个过程实现不同的功能 rncreate proc text rn(@a int rn) rnas rnrnif @a=0 rnbegin rnsql语句 rnend rnelse if @a=1 rnbegin rnsql语句 rnend rnelse rnbegin rnsql语句 rnend
sql存储过程或语句实时执行
如何实现每天的某个时刻执行粗出过程或语句.rn(有程序更好)
VBA中执行SQL存储过程的问题。
我在Excel中用如下VBA代码将当前EXCEL行记录插入到SQL 表。我想在VBA中加一段代码当所有Excel记录插入完成后再执行一个SQL的存储过程。请教如何实现?谢谢!rnrnVBA代码下:rncn.Open strCnrn'清空表记录rncn.execute "truncate table table1"rn'循环增加记录rnFor row = Me.TextBox1.Value To Me.TextBox2.Valuern strSQL = "insert into table1(供应商代码,物料代码,单位,不含税单价,供应商名称,物料名称) values ( '" & Sheet3.Cells(row, 1) & "','" & Sheet3.Cells(row, 2) & "','" & Sheet3.Cells(row, 3) & "','" & Sheet3.Cells(row, 4) & "','" & Sheet3.Cells(row, 5) & "','" & Sheet3.Cells(row, 6) & "')"rncn.execute strSQLrnNext rowrncn.Close
sqlserver定时自动执行SQL存储过程
(1)打开SQL Server Management Studio,SQL Server代理--作业--点右键--新建作业; (2)作业的名称取为:test 并进行说明,若作业的数量太多,以方便区别; 这里写上定时执行存储过程Pr_test 确定保存. (3)点击常规下面的步骤,按箭头指示,新建步骤. (4)取名步骤名称:
求助!!在vb中执行sql存储过程
在vb中执行sql存储过程后如何得到执rn行后的结果并将值送给一个变量,如下rnexec(select *from student where 姓名=‘aaa)rn如何将’aaa‘给一个变量。rn前提是在vb前台做这件事rn
sql存储过程中执行sql语句
今天写sql语句快写晕了,后来网上查到了资料自己又整理下,最终的代码备份一下 create proc [dbo].[search_ProductTakeStockView_byCP] @code varchar(50),@producctName varchar(50) as declare @s varchar(100) set @s='select * from ProductTa...
请教执行SQL存储过程中的技巧。
[code=SQL]rncreate proc GetArticlern(rn @string varchar(100),rn)rnasrnexec('select top 10 * from article where 1=1 '+@string+'')rn')rn[/code]rnrn这是一个存储过程,我@string参数想传的是一个SQL判断,比如 'and 1=1',但是提示错误,'+and 1=1+' 附近有语法错误。rn我这里设置 这个 参数,主要是 如果我有不固定的 判断语句需要写入的话,我直接都写在@string里,之后 执行SQL语句的时候 通过我@string中的条件判断,好查询出我想要的内容。希望大家帮帮忙!rn
SQL存储过程与C#的结合
用存储过程代替SQL语句 Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ex10_58", "Ex10_58\Ex10_58.csproj", "{F01CFD92-823F-4B9E-B153-9E83C3FCDB68}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {F01CFD92-823F-4B9E-B153-9E83C3FCDB68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F01CFD92-823F-4B9E-B153-9E83C3FCDB68}.Debug|Any CPU.Build.0 = Debug|Any CPU {F01CFD92-823F-4B9E-B153-9E83C3FCDB68}.Release|Any CPU.ActiveCfg = Release|Any CPU {F01CFD92-823F-4B9E-B153-9E83C3FCDB68}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal
c#,sql存储过程分页技术实现
c#,sql存储过程分页技术实现 主要运用sql存储过程进行分页实现,在进行分页实现,需要注意一下事项, * 在项目的根目录下面有一个db文件夹,请认真阅读,里面包含测试数据信息,当然你也可以 * 直接还原数据库即可
C# 调用SQl存储过程
现在SQlHelper中有这样一个数据库操作方法rn /// rn /// 执行带参数存储过程,返回数据集DataSetrn /// rn /// 存储过程名rn /// 参数列表rn /// 返回的数据集rn /// 操作状态rn public int DBRunProc(string procname, IDataParameter[] paras, ref DataSet ds)rn rn if (procname == null || procname == "")rn rn return -1;rn rn tryrn rn if (conn.State == ConnectionState.Closed)rn rn conn.Open();rn rn cmd.Connection = conn;rn cmd.CommandType = CommandType.StoredProcedure;rn cmd.CommandText = procname;rn cmd.Parameters.Clear();rn if (paras != null)rn rn foreach (IDataParameter Para in paras)rn rn cmd.Parameters.Add(Para);rn rn rn da = new SqlDataAdapter();rn da.SelectCommand = cmd;rn da.Fill(ds);rn return 0;rn rn catch (InvalidOperationException ex)rn rn return -1;rn rn catch (System.Data.SqlClient.SqlException ex)rn rn return -1;rn rn catch (System.Exception ex)rn rn return -1;rn rn finallyrn rn if (conn.State == ConnectionState.Open)rn rn conn.Close();rn rnrn rnrn rnsql中存储过程如下:rncreate proc up_examResultInfo(@UserCode varchar(20))rnasrnselect * from v_userRankrnwhere stuNum=@UserCode rnrn在SqlDAL中怎么写呢?以下是我写的,有问题rn public DataSet GetUserExamInfo(string userCode)rn rn 1. IDataParameter[] paras = new SqlParameter[1];rn 2. paras[0] = new SqlParameter("@UserCode", SqlDbType.VarChar, 20);rn 3. paras[0].Value = userCode;rn 4. DataSet ds = new DataSet();rn 5. ······rn 6. ······ rn rn我是想在UI的窗体中显示某个学员的所有科目信息,如何在按钮中调用GetUserExamInfo方法把数据显示到dataGridView1rn主要是5,6行怎么写?
C#操作sql存储过程问题?
各位:我想在c#中实现动态调用存储过程,也就是未知参数个数来调用运行存储过程(像pb动态sql)请问各位怎样实现?
C#调用sql存储过程分页
可以增加朋友们对ASP.NET中调用存储过程方法的一些了解
C#调用SQl存储过程
一个小程序无法获取分页后数据。请高手帮忙DeBug一下,留个地址我把源代码发过去!谢谢!
c#调用sql存储过程
我只想在c#调用sql存储过程,我有三个存储过程的名字叫tj,js,sc (即添加一列,计算数据,删除一列) rn请问如何使用代码调用它们!最好写我解释!!rn谢谢大家!
C# and ms sql存储过程问问题
//string StfId = Request.QueryString.GetValues("StfId").GetValue(0).ToString();rn //string QbNumber = Request.QueryString.GetValues("QbNumber").GetValue(0).ToString();rn //string Money = Request.QueryString.GetValues("Money").GetValue(0).ToString();rn//以上为取值,现在测试直接用rn string StfId = "12";rn string QbNumber = "2222222";rn string Money = "5";rnrn SqlConnection Conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("DataConnectionString"));rn Conn.Open();rnrnrn SqlCommand CmdUpdate = new SqlCommand("Pro_QbType", Conn);rn CmdUpdate.CommandType = CommandType.StoredProcedure;rn CmdUpdate.Parameters.Add("@StfId", SqlDbType.VarChar,4).Value = StfId;rn CmdUpdate.Parameters.Add("@QBValues",SqlDbType.VarChar,4).Value = Money;rnrnrnrn //建立并添加和“@QBcode OUTPUT”对应的参数rn SqlParameter parmReturnValue = new SqlParameter("@QBcode", SqlDbType.VarChar,20);rn //parmReturnValue.IsNullable = true;rn parmReturnValue.Direction = ParameterDirection.Output;rn CmdUpdate.Parameters.Add(parmReturnValue);rnrn CmdUpdate.ExecuteNonQuery();rn QBcode = CmdUpdate.Parameters["@QBcode"].Value.ToString();rnrn SqlTransaction Trans = Conn.BeginTransaction();rn tryrn rn CmdUpdate.Transaction = Trans;rn CmdUpdate.ExecuteNonQuery();rn QBcode =CmdUpdate.Parameters["@QBcode"].Value.ToString();rn Trans.Commit();rn CmdUpdate.Dispose();rn Conn.Close();rn rn catch (Exception Err)rn rnrn Response.Write(Err.Message);rn rn rn说明:rn在MS SQL2005中执行有返回值,在程序中测试就是为空?
c#中用sql存储过程
string connstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(connstr); SqlCommand comm = new SqlCommand();...
C#如何调用SQL存储过程
在工作中,经常遇到需要调用存储过程,如何调用呢? 下面实现的功能是判断某参数值,Fail时调用存储过程发送邮件至相关人员: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebContro...
C#调用sql存储过程
使用存储过程的优点和缺点优点1.降低网络传输数据量:通过存储过程的名称和参数传递即可调用执行,不用传输sql语句。2.执行效率高:sqlserver会事先将存储过程编译成可执行的二进制代码,运行存储过程时,无需再次编译。3.封装性:也可叫模块式编程,将实现某种功能的多条sql封装到一个对象中,可多次重复调用,可移植性强。4.安全:可针对不同的权限的用户使用不同的存储过程。缺点1.调试麻烦,但是用 ...
c#调用sql存储过程的步骤
String conn3 = "Data Source=WEINIU;Initial Catalog=sde;Persist Security Info=True;User ID=sa;Password=m";             SqlConnection connection3 = new SqlConnection(conn3);             string sql3 =
C# SQL存储过程输出问题
[code=SQL]rn--SQL存储过程问题rnALTER PROCEDURE [dbo].[proc_getservicebomfname] rn @fnames nvarchar(500) output, rn @orderno nvarchar(50), rnASrnBEGIN rn declare @oname nvarchar(500); rn set @oname='';rn select @oname=orderno+'--'+ordername+' >> ' from tborder where orderno=@orderno;rnrn select @fnames='abc'+@oname;rn if @@error <> 0rn select -1;rn elsern select 0;rnendrn[/code]rn以上为存储过程 。rn现在的问题是:我在企业管理器执行存储过程,@fnames参数的值输出正常,但在C#代码调用时,只输出:abcrn不知道是什么问题引起。为什么@oname的值不能用呢。请各位指点...
c#执行sql存储过程,出了怪事。专家指教 在线等
c#调用存储过程如下: rnstring strcon; rnstrcon = Code.Configuration.CONNECTIONSTRING; rnconn = new SqlConnection(strcon); rnconn.Open(); rnSqlCommand cmd = new SqlCommand("sp_creatMonthKCReport", conn); rncmd.CommandType = CommandType.StoredProcedure; rnSqlParameter sp_1 = new SqlParameter("@ny", SqlDbType.VarChar, 7); rnsp_1.Value ="2008-06"; rncmd.Parameters.Add(sp_1); rncmd.ExecuteNonQuery(); rnconn.Close(); rnrnrn该存储过程在查询分析器执行结果如下(正确): rnid value rn01 aaa rn02 bbb rn03 ccc rn在页面调用后结果如下(错误): rnid value rn01 aaa rn02 aaa rn03 aaa rn怀疑是“c#调用存储过程”的代码有错误,但是将参数直接写进存储过程后,还是不对。rnrnrn该存储过程在查询分析器执行结果完全正确 rnrn出错的代码段: rn--本月结存 rnrnDECLARE currMonthStore_cursor CURSOR FOR rnselect x.itembh,( case when x.buyTotalNums is null then 0-y.sellTotalNums else x.buyTotalNums-y.sellTotalNums end) as currMonthStore rnfrom (select a.itembh,b.buyTotalNums,b.buyTotalMoney rnfrom tmp_kctj1 a rnleft join (select itembh, rnsum(innum) as buyTotalNums, sum(inprice) as buyTotalMoney rnfrom dict_kcjh_item rnwhere '20'+substring(incode,3,2)+'-'+substring(incode,5,2) <=@currYearMonth rngroup by itembh) b rnon ( a.itembh=b.itembh)) x rnleft join (select a.itembh,b.sellTotalNums,b.sellTotalMoney from tmp_kctj1 a rnleft join (select y_a.clsbh,y_a.itembh,sum(y_a.num) as sellTotalNums,sum(y_a.subtotal) as sellTotalMoney rnfrom Buz_ScheduleDetail y_a left join Buz_ScheduleCard y_b on y_a.bh=y_b.bh rnwhere convert(char(7),y_b.ChargeDate,120) <=@currYearMonth rngroup by y_a.clsbh,y_a.itembh) b on ( a.itembh=b.itembh)) y rnon x.itembh=y.itembh rnrnOPEN currMonthStore_cursor rnrnFETCH NEXT FROM currMonthStore_cursor rnINTO @sp_buyItembh,@currMonthStore rnrn-- Check @@FETCH_STATUS to see if there are any more rows to fetch. rnWHILE @@FETCH_STATUS = 0 rnBEGIN rnrn --PRINT @sp_buyItembh rnrn --PRINT '售价'+@sp_buyUnitPrice rnrnupdate tmp_kctj1 set currMonthStore=@currMonthStore rnwhere itembh=@sp_buyItembh rn rn -- This is executed as long as the previous fetch succeeds. rn FETCH NEXT FROM currMonthStore_cursor rn INTO @sp_buyItembh,@currMonthStore rnrnEND rnrnCLOSE currMonthStore_cursor rnDEALLOCATE currMonthStore_cursor rnrn-------------------------------------- rnrn下面这段也是该存储过程的内容,但是没有出错。 rn--将本月采购信息更新至统计临时统计表 rnrnDECLARE buy_cursor CURSOR FOR rnselect a.itembh,b.buyTotalNums,b.buyunitprice from tmp_kctj1 a rnleft join (select itembh,'20'+substring(incode,3,2)+'-'+substring(incode,5,2) as ny, rnsum(innum) as buyTotalNums,-- sum(inprice) as buyTotalMoney, rn(case when (sum(innum) is null or sum(innum)=0) then '' else sum(innum*inunitprice)/sum(innum) end) as buyunitprice rnfrom dict_kcjh_item rngroup by '20'+substring(incode,3,2)+'-'+substring(incode,5,2),itembh) b on (a.ny=b.ny and a.itembh=b.itembh) rnrnrnOPEN buy_cursor rnrnFETCH NEXT FROM buy_cursor rnINTO @sp_buyItembh,@currMonthTotalBuyNums,@sp_buyUnitPrice rnrn-- Check @@FETCH_STATUS to see if there are any more rows to fetch. rnWHILE @@FETCH_STATUS = 0 rnBEGIN rnrn --PRINT @sp_buyItembh rnrn --PRINT '售价'+@sp_buyUnitPrice rnrnupdate tmp_kctj1 set currMonthBuyNums=@currMonthTotalBuyNums,buyunitprice=@sp_buyUnitPrice rnwhere itembh=@sp_buyItembh and ny=@currYearMonth rn rn -- This is executed as long as the previous fetch succeeds. rn FETCH NEXT FROM buy_cursor rn INTO @sp_buyItembh,@currMonthTotalBuyNums,@sp_buyUnitPrice rnEND rnrnCLOSE buy_cursor rnDEALLOCATE buy_cursor
SQL存储过程
一、存储过程概念 存储过程(stored procedure)是一组为了完成特定功能的SQL语句集合,经编译后存储在服务器端的数据库中,利用存储过程可以加速SQL语句的执行。 存储过程分为系统存储过程和自定义存储过程: 系统存储过程在master数据库中,但是在其他的数据库中可以直接调用,并且在调用时不必在存储过程前加上数据库名,因为在创建一个新数据库时,系统存储过程在新的数据库中会自动创建。 自...
sql存储过程
 sql语句执行的时候要先编译,然后执行。存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储在数据库中。用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它。存储过程是数据库中的一个重要对象,任何一个设计良好的数据库应用程序都应该用到存储过程。 [编辑本段]一、存储过程介绍   存储过程是由流控制和SQL语句书写的过程,这个过程经编...
相关热词 c#串口测试应用程序 c# 匹配 正则表达式 c#防止窗体重绘 c#读写txt文件 c#挖地雷源代码 c#弹框选项 c# 移除 队列 c# 密码写入配置文件 c# 获取可用内存大小 c# 嵌入excel编辑