Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
how to retrieve data from Sql server 2005 database using data reader and display it into textbox in c# ASP.net
Posted 2-Jan-13 22:02pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use this function to your required event
 
   private void loadData()
    {
       
            SqlCommand cmd = default(SqlCommand);
            SqlConnection con = default(SqlConnection);
            con = new SqlConnection("<your connection="" string="" here=""></your>");
            con.Open();
            cmd = new SqlCommand("<your query="" here=""></your>", con);
            SqlDataReader reader = cmd.ExecuteReader();
            TestBox1.Text = Convert.ToString(reader["<column name="" here=""></column>"]);
            con.Close();
     }
  Permalink  
Comments
Turbo_23 at 3-Jan-13 3:44am
   
or you can also use cmd.ExecuteScalar,
Member 9693583 at 3-Jan-13 3:51am
   
Hi,
Thanks for ur reply..
 
I m trying below mentioned code... But really don't understand where i m wrong... can u please help me out... i will be very glad...
thanks
 

using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
 
public partial class Callupdation : System.Web.UI.Page
{


private void loadData()
{

SqlCommand cmd = default(SqlCommand);
SqlConnection con = default(SqlConnection);
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Callregister_connectionstring"].ConnectionString);
con = new SqlConnection("SERVER=KSHITIJA-PC; Initial Catalog=CRM;Integrated Security=True" "Callregister_connectionstring");
con.Open();
cmd = new SqlCommand("Select * from Call_Reg ", con);
SqlDataReader reader = cmd.ExecuteReader();
txtFname.Text = Convert.ToString(reader["Cust_FName"]);
con.Close();
}
ujju.1 at 3-Jan-13 4:46am
   
whats the error/exception??
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

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

  Print Answers RSS
0 Kornfeld Eliyahu Peter 275
1 Maciej Los 214
2 Sergey Alexandrovich Kryukov 200
3 King Fisher 185
4 OriginalGriff 163
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100