fangjunhua 发表于 2008-5-21 20:30

求助!向数据库添加数据

protected void Button1_Click(object sender, EventArgs e)
        {
            string CustomerName=this .TextBox1 .Text.ToString();
            string Gender=this .TextBox2 .Text.ToString();
            string Age=this .TextBox3 .Text.ToString();
            string IDNumber=this .TextBox4 .Text.ToString();
            string Career=this .TextBox5 .Text.ToString();
            string Education=this .TextBox6 .Text.ToString();
            string Phone=this .TextBox7 .Text.ToString();
            string Address=this .TextBox8 .Text.ToString();
            string Zip=this .TextBox9 .Text.ToString();
            string Email=this .TextBox10 .Text.ToString();
            string CCount = "1";
            string BigCustomer;
            添加一段程序,如果Career的内容为“商业”,Age的内容为“大于30小于50”,并且Education的内容为“高等”,则BigCustomer为“YES”,否则为“No”。
            SqlConnection DBConnectionString = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["DBConnectionString"]);
            DBConnectionString.Open();
            SqlCommand scd = new SqlCommand("insert into Customer(CustomerName,Gender,Age,IDNumber,Career,Education,Phone,Address,Zip,Email,CCount,BigCustomer)values('" + CustomerName + "','" + Gender + "','" + Age + "','" + IDNumber + "','" + Career + "','" + Education + "','" + Phone + "','" + Address + "','" + Zip + "','" + Email + "','" + CCount + "','" + BigCustomer + "')", DBConnectionString);
            scd.ExecuteNonQuery();
            DBConnectionString.Close();Response.Write ("<script language=javascript>alert('您已经添加成功');location='Add_Customer.aspx'</script>");
           
        }
其中,Career,Education,BigCustomer等都为数据库字段。请高手帮我编写一下所要添加的那段程序,谢谢!

hxfly 发表于 2008-5-21 23:06

if(Career=="商业"&&Education=="高等"&&Convert.ToInt(Age)<30&&Convert.ToInt(Age)>50)
{
BigCustomer="YES"
}
else
{
BigCustomer="NO"
}


不知道这样可以不....

fangjunhua 发表于 2008-5-22 11:20

已经解决,谢了

[[it] 本帖最后由 fangjunhua 于 2008-5-22 11:22 编辑 [/it]]

页: [1]

编程论坛