标题:求助!向数据库添加数据
只看楼主
fangjunhua
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-5-7
 问题点数:0 回复次数:2 
求助!向数据库添加数据
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等都为数据库字段。请高手帮我编写一下所要添加的那段程序,谢谢!
搜索更多相关主题的帖子: string 数据库 ToString Text 
2008-05-21 20:30
hxfly
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:5807
专家分:108
注 册:2005-4-7
得分:0 
if(Career=="商业"&&Education=="高等"&&Convert.ToInt(Age)<30&&Convert.ToInt(Age)>50)
{
BigCustomer="YES"
}
else
{
BigCustomer="NO"
}


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

2008-05-21 23:06
fangjunhua
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-5-7
得分:0 
已经解决,谢了

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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-215505-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.253865 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved