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 = "";
}
}
}