asp.net执行sql语句(C#)

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

        //select选出结果集到dataset里面

 

        SqlConnection conn = new SqlConnection("server=localhost;database=KaoQin_320;user id=sa;Pwd=123");

        string sql = "select * from T_Hall";

        SqlDataAdapter sqldap = new SqlDataAdapter(sql, conn);

        DataSet ds = new DataSet();

        sqldap.Fill(ds);

     }

 

    protected void Button2_Click(object sender, EventArgs e)

    {

        //执行sql语句

 

        SqlConnection conn = new SqlConnection("server=localhost;database=KaoQin_320;user id=sa;Pwd=123");

        conn.Open();

        string sqladd = "insert into T_Hall (C_HallID,C_HallName,C_UpUnitID,C_UpUnitName) values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "')";

        SqlCommand commd = new SqlCommand(sqladd, conn);

        commd.ExecuteReader();

        conn.Close();

    }

}

你可能感兴趣的:(sql,object,C#,asp.net,textbox,dataset)