回覆列表
  • 1 # 使用者1465424935672

    SqlConnection conn = new Sqlconnection();

    conn.ConnectionString = ConfigurationManager.ConnectionStrings["MywebsiteConnectionString"].ToString(); //連線資料庫的字串,一般寫在webconfig裡

    conn.Open();

    SqlCommand cmd = new SqlCommand();

    cmd.Connection = conn;

    cmd.CommandText = "INSERT INTO 表名(欄位名一,欄位名二)VALUES(@引數一,@引數二)";

    cmd.Parameters.Add("@引數一",SqlDbType.Char).Value = TextBox1.Text.Trim();

    cmd.Parameters.Add("@引數二",SqlDbType.Char).Value = TextBox2.Text.Trim();

    int var = cmd.ExecuteNonQuery(); //執行資料庫命令

    if(var>0) //判斷資料庫命令是否執行成功

    {

    Response.Write("");

    }

  • 中秋節和大豐收的關聯?
  • aspx檔案怎麼開啟?