使用ADO.NET连接调用存储过程 [英] Calling a stored procedure using ADO.NET connection

查看:86
本文介绍了使用ADO.NET连接调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个表并存储了要插入的产品.我不知道如何在后面的代码中调用存储过程并插入数据.我使用ADO.NET进行连接

I have alreay created a table and stored produre for insert.Idon''t know how to call the stored procedure inthe code behind and insert data.Iam using ADO.NET for connection

推荐答案

http://support.microsoft.com/kb/310070 [在ADO.NET中调用存储过程 [ http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx [ ^ ]
http://support.microsoft.com/kb/310070[^]
Calling Stored procedures in ADO.NET[^]
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx[^]


cmd.Parameters.Clear();
                    cmd.Connection = con;
                    cmd.CommandText = "sp_StoredProcedureName";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@id", SqlDbType.Int).Value = Id;
                    cmd.Parameters.Add("@name", SqlDbType.Int).Value = Name;
                   
                    da = new SqlDataAdapter();
                    da.SelectCommand = cmd;
                    da.Fill(ds, " ");


尝试一下



try this



DataSet ds = new DataSet();
SqlConnection sqlConn = new SqlConnection("your connection string");
SqlCommand sqlCmd = new SqlCommand(storedprocedurename, sqlConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCmd);
sqlAdapter.Fill(ds);


这篇关于使用ADO.NET连接调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆