您的位置:程序门 -> .net技术 -> vb.net



select distinct 这个语法难倒了“reader = mycomm.EXECutereader”这句么?为什么不能执行


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


select distinct 这个语法难倒了“reader = mycomm.EXECutereader”这句么?为什么不能执行[已结贴,结贴人:newlysl]
发表于: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
发表于:2007-04-19 18:26:071楼 得分:20
试一下用   select   count   *   from   teacher   where   教师名=   ' "   &   trim(textbox2.text)   &   " '   and   密码=   ' "   &   trim(textbox3.text)   &   " ' "

若值为   0   则允许新增.
发表于:2007-04-19 18:37:422楼 得分:0
我试了,显示“在关键字   'from '   附近有语法错误。”
我又把*写成(*),又显示“列名   '教师名 '   无效。”
发表于:2007-04-19 18:49:313楼 得分:0
行了,行了,成功了,是(*),
是我刚才“where   教师名”这里写错了,哈哈,应该是“where   老师名”
谢谢你啊,帮了个不小的忙!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
发表于:2007-04-19 18:54:134楼 得分:0
晕,不好意思,刚才我用的实验是老师名和密码原记录上已经有过的,但是现在我只取老师名或者密码其中1个和原记录一样,也返回msgbox( "不允许添加这样巧合的记录 "),这是为什么啊?


快速检索

最新资讯
热门点击