如何使用C#从asp.net中的存储过程获取价值 [英] How to get value from stored procedure in asp.net using C#
本文介绍了如何使用C#从asp.net中的存储过程获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友...
在我的Web应用程序报告页面中.
我需要通过从前端传递值来从数据库获取报告.
如何通过stord过程传递值和获取值.
您能帮我吗
Hi Friend...
In my web application report page is there.
I need to take report from DB ,by passing value from front end.
How to pass value and get value from stord procedure.
Can u please help me
推荐答案
使用以下代码:
Use the below code:
SqlConnection cn = new SqlConnection("your connection string");
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText="storedprocedure name";
cmd.CommandType=CommandType.StoredProcedure;
cmd.Parameters.Add("value in sp","datatype of that value","size").value="your value to be passed".
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,"tbl");
然后您将表格放入数据集"ds".
您可以将它们检索为:
then you will get the table into the dataset "ds".
you can retrieve them as:
ds.Tables[0].Rows[0]["cellname"].ToString();
本文介绍了执行此操作的方法.
了解ADO.NET的初学者教程 [ ^ ]
This article shows the way to do it.
A Beginner''s Tutorial for Understanding ADO.NET[^]
您需要使用SQL注入.
诸如
之类的东西
You need to use SQL injection.
Some thing like
Sqlcommand com = new SqlCommand("Select * from <tablename> where name=@name",con);
com.parameters.addWithValue("@name",textboxname);
这篇关于如何使用C#从asp.net中的存储过程获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文