Asp.net源码专业站
首页->新闻文章->Handson简单新闻系统后台源码>>NewsClassManage/ClassAdd.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:Handson简单新闻系统后台源码
当前文件:文件类型 HandsonNews/NewsClassManage/ClassAdd.aspx.cs[3K,2009-6-12 11:43:42]打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using System.Data.SqlClient; 12 13public partial class NewsClassManage_ClassAdd : System.Web.UI.Page 14{ 15 protected void Page_Load(object sender, EventArgs e) 16 { 17 //第一个文本框获得焦点 18 this.TxtClassName.Focus(); 19 20 } 21 protected void BtnSaveClass_Click(object sender, EventArgs e) 22 { 23 //记录所影响的行数 24 int reader; 25 //建立连接 26 SqlConnection con = DataAccess.CreateConnection(); 27 //执行数据库insert语句 28 SqlCommand com = new SqlCommand("insert into t_class(classname,itemid,classdesc,classorder) values(@classname,@itemid,@classdesc,@classorder)", con); 29 //将文本框的值传入到数据库t_Class表中 30 com.Parameters.Add("@classname", SqlDbType.VarChar).Value = this.TxtClassName.Text; 31 com.Parameters.Add("@itemid",SqlDbType.VarChar).Value = this.DdlClassItemName.SelectedItem.Value; 32 com.Parameters.Add("@classdesc", SqlDbType.VarChar).Value = this.TxtClassDesc.Text; 33 com.Parameters.Add("@classorder", SqlDbType.VarChar).Value =this.TxtClassOrder.Text; 34 try 35 { 36 //判断分类名称是否为空,为空给出提示,并把分类名称一栏设为焦点 37 if (this.TxtClassName.Text == "") 38 { 39 //<script>window.alert</script>给出一个提示对话框 40 Response.Write("<script>window.alert('分类名称不能为空!')</script>"); 41 this.TxtClassName.Focus(); 42 } 43 else 44 { 45 //判断分类顺序一栏输入的是否是整数 46 int a = int.Parse(this.TxtClassOrder.Text); 47 //打开数据连接 48 con.Open(); 49 //执行命令对象 50 reader = com.ExecuteNonQuery(); 51 //查看所影响行数,如果为零 52 if (reader == 0) 53 { 54 Response.Write("<script>window.alert('操作失败!')</script>"); 55 } 56 else 57 { 58 Response.Write("<script>window.alert('操作成功!')</script>"); 59 //把所有文本框置空 60 this.TxtClassName.Text = ""; 61 this.TxtClassDesc.Text = ""; 62 this.TxtClassOrder.Text = ""; 63 } 64 } 65 66 } 67 catch (FormatException) 68 { 69 //给出提示,分类顺序一栏应输入整数 70 Response.Write("<script>window.alert('分类顺序一栏必须输入整数,请重新输入!')</script>"); 71 //分类顺序一栏获得焦点,同时把文本框的值置为零 72 this.TxtClassOrder.Focus(); 73 this.TxtClassOrder.Text = ""; 74 } 75 finally 76 { 77 //关闭数据连接 78 con.Close(); 79 } 80 81 82 } 83} 84
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:Handson简单新闻系统后台源码
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146