Please can somebody tell me how to show data in datagridview through dataadapter and dataset from data base...
Please reply me quickly i need it. it's urgent
Regards
Zeb
Loading
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 attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 12, 2011, 4:22 AM EST
Try this...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Datagridview_bind
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from customer";
com = new OleDbCommand(str, con);
oda = new OleDbDataAdapter(com);
ds = new DataSet();
oda.Fill(ds, "customer");
dataGridView1.DataMember = "customer";
dataGridView1.DataSource = ds;
con.Close();
}
}
}
Thanks
Zeb Rehman41 reputationPosted Dec 12, 2011, 4:29 AM EST
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 12, 2011, 4:52 AM EST
str = "select custid,custname from customer";
Here custid and custname will be displayed in the datagridview.If you use * all columns will be displayed in the datagridview.
Thanks
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 12, 2011, 6:12 PM EST
If this post helps you mark it as answer
Thanks
Zeb Rehman41 reputationPosted Dec 12, 2011, 9:48 PM EST