Click here to Skip to main content
14,836,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...
Posted

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...

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



Hope this will help...
   
v2
You need to use ADO.NET classes if you are to perform the task programatically

C# code

C#
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();
}


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.......
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900