我不知道我的代码出了什么问题,即使我通过许多堆栈溢出讨论浏览过,并且与在数据网格中填充结果的方式相同。 有人能告诉我这里有什么问题:
private void frmGridVw_Load(object sender, EventArgs e)
{
string connectionString = "Data Source=.;Initial Catalog=AdventureWorks;User ID=sa";
string selectString = "Select Title, FirstName, LastName, Suffix, EmailAddress " +
"From AdventureWorks.Person.Contact " +
"Where Suffix = 'Jr.'";
SqlConnection mySqlConnection = new SqlConnection(connectionString);
mySqlConnection.Open();
SqlDataAdapter dataAdapter = new SqlDataAdapter(selectString, mySqlConnection);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
dataGridView1.ReadOnly = true;
dataGridView1.DataSource = ds.Tables[0];
}