帮忙解决连接数据库问题
一个表单只有button 与dataGridView 两个控件,现要点击button ,在dataGridView中显示查询的数据,但下面的语句怎么不行帮忙看看,
private void button1_Click(object sender, EventArgs e)
{
string strcon = " Integrated Security=SSPI;Initial Catalog=pubs ";
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
string strsql = "select * from jobs ";
SqlCommand command = new SqlCommand(strsql, conn);
try
{
command.ExecuteNonQuery();
MessageBox.Show( "提交成功 ");
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message.ToString());
}
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds);
this.dataGridView1.DataSource = ds.Tables;
try
{
if (this.dataGridView1.DataSource == null)
MessageBox.Show( "显示错误 ");
else
&nbs