string str = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(str))
{
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = this.textBox1.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt;
MessageBox.Show("已完成!!!");
this.textBox1.Text = "";
}
}
private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(str))
{
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = this.textBox1.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt;
MessageBox.Show("已完成!!!");
this.textBox1.Text = "";
}
}
}
使用配置管理器设置数据库连接并填充数据网格

被折叠的 条评论
为什么被折叠?



