How to retrieve data from database onto asp table??
How to retrieve data from database onto asp(front end web page) table??
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 6, 2009, 2:03 AM EDT
asif basha33 reputationPosted Oct 6, 2009, 2:40 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 6, 2009, 3:24 AM EDT
Here is Code I have written for it take a Look
dont forget to mark "Do you like answer" it will give me some credits :)
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand comm = new SqlCommand("Select * from Users", con);
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
TableRow r = new TableRow();
TableCell c1 = new TableCell();
TableCell c2 = new TableCell();
c1.Text = reader["Username"].ToString();
c2.Text = reader["Password"].ToString();
r.Cells.Add(c1);
r.Cells.Add(c2);
Table1.Rows.Add(r);
}
}
Roei BarRank #1,271 · 1.4K reputationPosted Oct 6, 2009, 4:01 AM EDT
String strConn = "Server = .\\sqlexpress;Database = NorthWind;Integrated Security = SSPI;";dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;conn = new SqlConnection(strConn);da = new SqlDataAdapter("Select Categories.CategoryName, Products.ProductName, Products.UnitPrice From Categories Inner Join Products on Products.CategoryID = Categories.CategoryID", conn);SqlCommandBuilder cmd = new SqlCommandBuilder(da);ds = new DataSet();da.Fill(ds, "Categories");bs = new BindingSource(ds, "Categories");dataGridView1.DataSource = bs;bindingNavigator1.BindingSource = bs;using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace CSharpBindingSource { public partial class Form1 : Form { SqlDataAdapter da; SqlConnection conn; DataSet ds; BindingSource bs; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { String strConn = "Server = .;Database = NorthWind;Integrated Security = SSPI;"; conn = new SqlConnection(strConn); da = new SqlDataAdapter("Select * From Employees", conn); SqlCommandBuilder cmd = new SqlCommandBuilder(da); ds = new DataSet(); da.Fill(ds, "Employees"); bs = new BindingSource(ds, "Employees"); dataGridView1.DataSource = bs; bindingNavigator1.BindingSource = bs; } private void toolStripButton1_Click(object sender, EventArgs e) { bs.EndEdit(); da.Update(ds, "Employees"); } } }