日期:2014-05-18  浏览次数:20455 次

怎么把页面上录入的信息在按了提交按钮后存入到数据库的表中?
怎么把页面上录入的信息在按了提交按钮后存入到数据库的表中?比如我有三个TextBox文本输入框,ID名分别为job_name,job_address,job_telephone.我在三个文本框中输入的信息在点击了Button按钮(Button按钮名为Button)后要能存入数据库Person的表HY_GRXX中。如图

------解决方案--------------------
C# code

protected void Button1_Click(object sender, EventArgs e)
{
    string name = job_name.Text;
    string address = job_address.Text;
    string telephone = job_telephone.Text;
    SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["连接字符串"]);
    conn.Open();
    SqlCommand cmd = new SqlCommand("", conn);
    cmd.CommandText = "insert into HY_GRXX (job_name,job_address,job_telephone) value ('" + name + "','" + address + "','" + telephone + "')";
    int i = cmd.ExecuteNonQuery();
    if (i > 0)
    {
        Response.Write("<script>alert('提示信息:操作成功!');</script>");
    }
    conn.Close();
}