贴子漏了一个字,不好意思在sqlserver2000存储过程中,使用select * from .... 返回一个数据集,
但这个数据集只有一行,现在我要把存储过程封装在一个c#函数中,
在asp.net页面的后台的c#文件调用该函数。
但我需要取出每一列的值(只有一行)。也即把每列值赋给相应的参数。
请问应该如何主调用存储过程,如何定义函数的参数?
由于存储过程不是我编写的,所以不能修改存储过程。
谢谢!
但这个数据集只有一行,现在我要把存储过程封装在一个c#函数中,
在asp.net页面的后台的c#文件调用该函数。
但我需要取出每一列的值(只有一行)。也即把每列值赋给相应的参数。
请问应该如何主调用存储过程,如何定义函数的参数?
由于存储过程不是我编写的,所以不能修改存储过程。
谢谢!
解决方案 »
- ajax局部更新的问题
- gridview里checkbox和行点击事件分离的做法
- 创建WEB应用程序时需要输入用户名和密码
- 为什么本机不显示错误,到网上显示?
- [移动WEB]如何能获取到可以用来唯一识别的手机或手机卡的信息?
- 关于调用调用excel程序生成EXCEL文档的问题
- 我在做手机网站程序,服务器端怎么能取到手机的唯一标识?
- 推荐个免费开源的OA来用用
- help !!!!!!!!!!!!help me !!!!!how can help me
- DataGrid的问题11!!!
- 用DataSet绑定datagrid后,怎么取出DateSet来操作?
- 基于Exchange Server的企业应用系统设计和开发 ,请高手给于一点见意,和书籍参考
这是从IBuySpy里拿的一段调用存储过程的函数,参考一下. public SqlDataReader GetSingleUser(String email)
{ // Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("Portal_GetSingleUser", myConnection); // Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure; // Add Parameters to SPROC
SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 100);
parameterEmail.Value = email;
myCommand.Parameters.Add(parameterEmail); // Open the database connection and execute the command
myConnection.Open();
SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); // Return the datareader
return dr;
}
Dim conn As New SqlConnection("Server=localhost;user id=sa;password=xxx;database=Northwind;")
Dim cmd As New SqlCommand
cmd.CommandText = "test"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = conn
Try
conn.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Dim dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Do While dr.Read
response.write(dr("CategoryName") & "<br>")
Loop
as
select * from categories
GO
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "test";
da.SelectCommand = cmd;
da.Fill(ds, yourtablename);
呵呵,不过说句实在的,如果是分层大系统的话,最好还是不要象我这样写
写个数据访问基类,里面封装一系列的RunProcedure方法。参数即使没有的话也要把他设为null
楼主我来回答你这个问题:如有不对,请指正;
漏的一个字是:
也即把每列值赋给相的参数
也即把每列值赋给相应的参数。
----------------------
1:
private void getPara(out string name , out string psd)
{
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection(conStr);
cmd.Connection = con;
cmd.CommandText = "test";
con.open();
SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (sdr.Read())
{
name = sdr[0]; //name = sdr["name"];
psd = sdr[1]; //psd = sdr["password"];
}
}
//调用方法;
........
string sn , sp;
getPara(out sn ,out sp);
this.TextBox1.Text = sn;
this.TextBox2.Text = sp;
........
在getPara的最后加一句;
cmd.Close();//connection 将会自动关闭; 不需理会;
------------------------------
喜欢对你有帮助(我想要分,分,哈哈)
SqlDataAdapter sqledit = new SqlDataAdapter("Getchose",conn.myConnection);
sqledit.SelectCommand.CommandType=CommandType.StoredProcedure;
sqledit.SelectCommand.Parameters.Add("@ID",System.Data.SqlDbType.Int);
sqledit.SelectCommand.Parameters["@ID"].Value=GetID;
DataSet dsedit = new DataSet();
sqledit.Fill(dsedit,"editTable");
============================
此段调用了个Getchose的存储过程,传递了一个ID的参数,返回数据fill到了一个DataTable editTable中,然后你就可以在程序中对返回的数据进行操作了。