执行SQL

来源:互联网 发布:core java第十版中文版 编辑:程序博客网 时间:2024/05/16 17:45
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 = "";
}
}

}


原创粉丝点击