title: How to create a graph in C# using SQL Server database?
body: <p>I'm using a <code>SQL Server</code> database and <code>C#</code> form, I want to create a <code>graph</code> in C# form with database data.</p>
  
  <p>I use msdn sample codes but it didn't work; no error and no response!<br>
  Thank you for helping me ;)</p>
  
  <pre><code>// The Access database
  string fileNameString = "data\\chartdata.mdb";
  
  // Initialize a connection string   
  string myConnectionString = "Data Source=" + fileNameString;
  
  // Define the database query    
  string mySelectQuery="SELECT Name, Sales FROM REPS ;";
  
  // Create a database connection object using the connection string  
  SqlConnection myConnection = new SqlConnection(myConnectionString);
  
  // Create a database command on the connection using query  
  SqlCommand myCommand = new sqlCommand(mySelectQuery, myConnection);
  
  // Open the connection  
  myCommand.Connection.Open();
  
  // Create a database reader 
  SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
  
  chart1.Series["Default"].Points.DataBindXY(myReader, "Name", myReader, "Sales");
  
  // Close the reader and the connection
  myReader.Close();
  myConnection.Close();
  </code></pre>