Data bind in Chart control

Here we use DataBind method of chart control

using System.Web.UI.DataVisualization.Charting;

private void Page_Load(object sender, System.EventArgs e)
{
// Resolve the address to the Access database
string fileNameString = this.MapPath(“.”);
fileNameString += “..\\..\\..\\data\\chartdata.mdb”;

// Initialize a connection string
string myConnectionString = “PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=” + fileNameString;

// Define the database query
string mySelectQuery=”SELECT * FROM REPS;”;

// Create a database connection object using the connection string
OleDbConnection myConnection = new OleDbConnection(myConnectionString);

// Create a database command on the connection using query
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

// Set chart data source
chart1.DataSource = myCommand;

// Set series members names for the X and Y values
chart1.Series[“Series 1”].XValueMember = “Name”;
chart1.Series[“Series 1”].YValueMembers = “Sales”;

// Data bind to the selected data source
chart1.DataBind();
}

Advertisements

About Asif
Hello Friends… I have done my Bachelor of Engineering in Information Technology from Gujarat University. I have 1.7 years experience of web and windows based application development.. My basic idea to start a blog is to store all important link which help me in my application and access to every where. Also this information is help others who want to makes their application powerful. I am interested in .net framework (1.0,2.0,3.0,3.5 and more). This blog contain also many information related to SQL, Custom Controls in C#.net Please share your ideas and any query if you have...

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: