Click here to Skip to main content
Rate this: bad
good
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
Comments
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
good
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)
    {
        con.Open();
 
        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 !!!
  Permalink  
v2
Comments
damodara naidu betha at 11-Oct-12 5:54am
   
Correction..
 
while(dr.Read())
{
TextBox1.Text +=dr[0].ToString()+" ";
TextBox2.Text +=dr[1].ToString()+" ";
}
con.close()
Rate this: bad
good
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#[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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

try
{
//SqlCommand(query,connection)
SqlCommand cmd = new SqlCommand("Update tabel TableName set EmpName='" + textBoxEmpName.Text + "' where EMPID="+textBox1.Text+"", con)
;
cmd.ExecuteNonQuery();
}
catch(Exception c)
{
}
 

try this
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 10 Apr 2014
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