Click here to Skip to main content
11,706,799 members (47,718 online)
Rate this: bad
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 2:33am
Wes Aday at 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 at 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
0 OriginalGriff 156
1 Sergey Alexandrovich Kryukov 155
2 chainerlt 110
3 ppolymorphe 91
4 Mika Wendelius 70
0 OriginalGriff 9,190
1 Sergey Alexandrovich Kryukov 8,407
2 CPallini 5,189
3 Maciej Los 4,756
4 Mika Wendelius 3,686

Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 10 Apr 2014
Copyright © CodeProject, 1999-2015
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