Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Streamline data populatation into datagrid/Datagridview like Sqlserver Management Studion
 

Streamline data populatation into datagrid/Datagridview like Sqlserver Management Studion

hi
all can any body tell me how do i stream data into datagrid/datagridview like sql server management studio.
when we open a table in sql server it populate data into datagrid , same time it retrieve data from database.

if anybody have any idea please help.
  • Moved byVMazurMVPWednesday, September 09, 2009 10:36 AM (From:ADO.NET DataSet)
  •  
arup08  Friday, September 04, 2009 10:38 AM

Hi arup08,

You can use sqldataadapter to achieve this. Here is the example code:

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx

You can just set the datagridview’s datasource as dataset.Tables[0].

The connection string for SQL Server:

http://www.connectionstrings.com/sql-server-2005#111

Does this works for you? If you have any questions or concerns, please update the thread and we will have a further discussion.

Best Regards

Yichun Feng

Yichun_Feng  Monday, September 07, 2009 6:34 AM
hiYichun_Feng
thanks for your kind information but it didn't solved my problem.
what exactly my problem is, if i bound one millon recordset to dataset & then to datagrid/datagridview
it freeze whole UI interface or if i used background worker it blank some time.
i want to show row by row updation of a grid like when i open table in sqlserver mamanagement studio
it show row updation & taken a few seconds.

similarly i have dev. a program by this code
but its taken long time.

my code..........

public partial class Form1 : Form
{
string constr1 = "server=localhost;uid=sa;pwd=Password123;initial catalog=Test_Data";

private delegate void UpdateGridDelegate(DataTable ds);

BindingList<People> bindPeople = new BindingList<People>();
BindingSource bindingSource = new BindingSource();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
}

private void button1_Click(object sender, EventArgs e)
{
progressBar1.Value = progressBar1.Minimum;

// Start progres
this.progressTimer.Start();

// Set Cursor
this.Cursor = Cursors.AppStarting;


bindPeople.Clear();

bindingSource.DataSource = bindPeople;
dataGridView1.DataSource = bindingSource;

backgroundWorker1.RunWorkerAsync();

}

private void PopulateData()
{

int progressChunk = 0;

BindingList<People> blPeople = new BindingList<People>();

People peop;

DataSet dsRecords = new DataSet();
DataTable tab = new DataTable();
dsRecords.Tables.Add(tab);

string strSql = "Select * from mst_introducer";
SqlConnection con = new SqlConnection(constr1);
SqlCommand com = new SqlCommand(strSql, con);
con.Open();


//IAsyncResult result = com.BeginExecuteReader();


SqlDataReader reader = com.ExecuteReader();

while (reader.Read())
{
peop = new People(reader["INTRODUCER_CODE"].ToString(), reader["INTRODUCER_NAME"].ToString(), reader["ADDRESS"].ToString());

this.backgroundWorker1.ReportProgress(0, peop);


// give the UI thread a chance to update screen.
progressChunk++;
if (progressChunk > 10)
{
Thread.Sleep(120);
progressChunk = 0;
}
//blPeople.Add(peop);
}

con.Close();
reader.Close();

//return blPeople;
}


private void UpdateNoOfRows()
{
this.statusLabel.Text = String.Format("{0} Records Found", bindPeople.Count);
}



private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
PopulateData();
}

private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// Set Cursor
this.Cursor = Cursors.Default;
this.UseWaitCursor = false;

// Turn off
this.progressTimer.Stop();
this.progressTimer.Interval = 1000;

MessageBox.Show("Completed");
}

private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
People pep = e.UserState as People;

bindPeople.Add(pep);
UpdateNoOfRows();

}

private void timer1_Tick(object sender, EventArgs e)
{

// Slow down
this.progressTimer.Interval = (this.progressTimer.Interval * 3);

// Update progress bar
if ((this.progressBar1.Value + this.progressBar1.Step) > this.progressBar1.Maximum)
{
this.progressBar1.Value = this.progressBar1.Minimum;
}
else
{
this.progressBar1.Value += this.progressBar1.Step;
}

}

}



//-------------------------------------------------------------------



using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace WinTest
{
class People:INotifyPropertyChanged
{

private string Member_Code = string.Empty;
private string Member_Name = string.Empty;
private string Member_Address = string.Empty;

public People(string strcode, string strname, string strAddress)
{
MemberCode = strcode;
MemberName = strname;
Address = strAddress;

}

public string MemberCode
{
get
{ return Member_Code; }

set
{
if (value != Member_Code)
{
// Set Path
Member_Code = value;
OnPropertyChanged(new PropertyChangedEventArgs("MemberCode"));
}
}
}

public string MemberName
{
get
{
return Member_Name;
}
set
{
if (value != Member_Name)
{
// Set Path
Member_Name = value;
OnPropertyChanged(new PropertyChangedEventArgs("MemberName"));
}
}

}


public string Address
{
get
{
return Member_Address;
}
set
{
if (value != Member_Address)
{
// Set Path
Member_Address = value;
OnPropertyChanged(new PropertyChangedEventArgs("Address"));
}
}

}






#region INotifyPropertyChanged Members

protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (null != this.PropertyChanged)
{
PropertyChanged(this, e);
}
}

public event PropertyChangedEventHandler PropertyChanged;

#endregion



}
}









arup08  Wednesday, September 09, 2009 7:07 AM

You can use google to search for other answers

Custom Search

More Threads

• BindingNavigator Current Position with DataGridview ???
• DropDownList in VB.Net
• what is equivalent way of loading hierarchical data in datagridview using dataset (like .Net 1.1 Datagrid)
• Problem in using datacolumn expression and aggregate functions
• how to get the Primary & Foreign Keys to casade properly?
• Web DataGrid Selection
• dataGridView issue
• How to re-paint MDI image background
• Examining user-entered info in a datagridview control
• Draw Rectangle or Bold Border on selected Cell in DataGridView