Esempio n. 1
0
    void updatePublisher()
    {
        try
        {
            SqlConnection conn = new SqlConnection(strConn);
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            //UPDATE 語法
            SqlCommand sqlCmd = new SqlCommand(
                "UPDATE publisher_master_table SET "
                + "publisher_name = @publisher_name WHERE publisher_id = '" + PublisherIDTextBox.Text.Trim() + "'", conn);

            //接收TextBox值
            sqlCmd.Parameters.AddWithValue("@publisher_name", PublisherNameTextBox.Text.Trim()); //Trim 移除前後空白
            sqlCmd.ExecuteNonQuery();
            conn.Close();
            Response.Write("<script>alert('Publisher update successful!');</script>");
            clearTextBox();
            PublisherGridView.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message + "');</script>");
        }
    }
Esempio n. 2
0
    void signUpNewPublisher()
    {
        try
        {
            SqlConnection conn = new SqlConnection(strConn);
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            //INSERT INTO語法
            SqlCommand sqlCmd = new SqlCommand(
                "INSERT INTO publisher_master_table"
                + "(publisher_id, publisher_name)"
                + "VALUES(@publisher_id, @publisher_name)", conn);

            //接收TextBox值
            sqlCmd.Parameters.AddWithValue("@publisher_id", PublisherIDTextBox.Text.Trim()); //Trim 移除前後空白
            sqlCmd.Parameters.AddWithValue("@publisher_name", PublisherNameTextBox.Text.Trim());
            sqlCmd.ExecuteNonQuery();
            conn.Close();
            Response.Write("<script>alert('Add publisher successful!');</script>");
            clearTextBox();
            PublisherGridView.DataBind(); //Grid auto refresh after insert data
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message + "');</script>");
        }
    }
Esempio n. 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     PublisherGridView.DataBind();
 }