| 发表于:2007-04-19 17:53:08 楼主 |
protected sub button1_click(byval sender as object, byval e as system.eventargs) handles button1.click dim conn as new sqlconnection dim mycomm as new sqlcommand if textbox2.text = " " or textbox3.text = " " or textbox4.text = " " then msgbox( "警告:请填写完整信息(第一个文本框可以不填) ", msgboxstyle.okonly) response.redirect( "tea.aspx ") lblmsg.text = "......出错了 " end if dim reader as sqldatareader conn.connectionstring = "data source=(local);uid=sa;pwd=;database=kejian; " conn.open() mycomm.connection = conn mycomm.commandtext = "select distinct 教师名,密码 from teacher where 教师名= ' " & trim(textbox2.text) & " ' and 密码= ' " & trim(textbox3.text) & " ' " reader = mycomm.EXECutereader if reader.read = true then msgbox( "不允许添加这样巧合的记录 ") '我是想在textbox2(对应 "教师名 "字段和textbox3(对应 "密码 "字段)中如果输入了在teacher表中已经有如a(教师名),b(密码)这样的记录(同1个记录中)组合,那么就返回错误,即想表达这句:msgbox( "不允许添加这样巧合的记录 "),可是没能如愿 response.redirect( "tea.aspx ") lblmsg.text = "......出错了 " else mycomm = new sqlcommand( "insert into [teacher] (老师名,密码,所属院系) values( ' " & trim(textbox2.text) & " ', ' " & trim(textbox3.text) & " ', ' " & trim(textbox4.text) & " ' ) ", conn) mycomm.EXECutenonquery() conn.close() response.redirect( "tea.aspx ") lblmsg.text = "......添加成功 " end if end sub |
|
|
|
|