Click here to Skip to main content
12,691,097 members (30,901 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
how can i fetch data from sql server 2008 and insert that all into different text box. please help me on this
Posted 7-Oct-12 3:33am
Wes Aday 7-Oct-12 8:57am
You connect to your server, query the tables for the data the you want to display, and then assign the results to your textboxes.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
    SqlConnection con = new SqlConnection("server=Harshit-PC; database=Temp; uid= sa;pwd=india");
    SqlDataReader dr;
    SqlCommand cmd;
    protected void Page_Load(object sender, EventArgs e)

        string FetchData = "Select * from cus where Name='fb'";
        cmd = new SqlCommand(FetchData, con);
        dr = cmd.ExecuteReader();

        if (dr.Read())

            TextBox1.Text = dr[0].ToString();
            TextBox2.Text = dr[1].ToString();


Please tell me if not working !!!
damodara naidu betha 11-Oct-12 5:54am

TextBox1.Text +=dr[0].ToString()+" ";
TextBox2.Text +=dr[1].ToString()+" ";
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Well, by using a Connection String[^] you can connect to database.

Further info regarding the data communication can be read here:
MSDN: Accessing data with ADO.NET[^]
Beginners guide to accessing SQL Server through C#[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

On Search Click

DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter("Select * from TableName where EMPID="+textBox1.Text+" ",con);
// dt.Rows[index][ColumnName]
textBoxEmpName.text = dt.Rows[0]["Emp_Name"].ToString();

On Update Click

SqlCommand cmd = new SqlCommand("Update tabel TableName set EmpName='" + textBoxEmpName.Text + "' where EMPID="+textBox1.Text+"", con)
catch(Exception c)

try this

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170117.1 | Last Updated 10 Apr 2014
Copyright © CodeProject, 1999-2017
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