从数据库检索数据 [英] Retrieve data from Database

查看:128
本文介绍了从数据库检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是asp.net c#的初学者,我想使用SQL存储过程将数据从数据库和显示检索到ASP.NET文本框控件中.请帮助我...

Hi, I am a beginner in asp.net c# and I want to Retrieve data from Database & Display into ASP.NET Textbox controls using SQL Stored Procedure?. plz help me...

推荐答案

您可以使用ADO.net从数据库中检索数据.

如果只希望数据库中的单个值显示在Textbox 中,则可以使用ExecuteScalar() ...

我假设您正在使用SQL Server数据库..请单击以下链接: http ://msdn.microsoft.com/zh-CN/library/system.data.sqlclient.sqlcommand.executescalar.aspx [
you can use ADO.net to retrieve data from database.

If you want only single value from database to display in Textbox then you can use ExecuteScalar() ...

I am assuming you are using SQL server database.. Follow this link : http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx[^]



If you want to use Stored Procedure instead of Inline query then set CommantType attribute as given below...

System.Data.SqlClient.SqlCommand objCommand = new System.Data.SqlClient.SqlCommand();
                objCommand.CommandType = System.Data.CommandType.StoredProcedure;




希望这对您有帮助...




Hope this will help...


如果要以编程方式执行任务,则需要使用ADO.NET类.

C#代码

You need to use ADO.NET classes if you are to perform the task programatically

C# code

using System.Data.SqlClient;

//in your class or method .........
SqlConnection con=new SqlConnection("write connection string here");
con.Open();

SqlCommand cmd=new SqlCommand("my_procedure",con);
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
textBox1.Text=dr[0].ToString();
}



这些链接可能会有所帮助
如何使用以下方法将数据从sql数据库显示到文本框C#.net [ http://forums.cnet.com/7723-6615_102-219037.html [ ^ ]


使用此代码祝你好运" .......



these links may be helpful
how to display data from sql database to textbox using C#.net[^]

http://forums.cnet.com/7723-6615_102-219037.html[^]


Use this code Best of Luck.......


这篇关于从数据库检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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