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



奇怪数据库不能更新   vb.net


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


奇怪数据库不能更新 vb.net
发表于:2007-06-12 21:38:33 楼主
代码如下..
imports   system.data
imports   system.data.sqlclient
imports   system.data.oledb
public   class   editinfo
        inherits   system.web.ui.page

#region   "   web   窗体设计器生成的代码   "

        '该调用是   web   窗体设计器所必需的。
        <system.diagnostics.debuggerstepthrough()>   private   sub   initializecomponent()

        end   sub
        protected   withevents   button1   as   system.web.ui.webcontrols.button
        protected   withevents   dropdownlist1   as   system.web.ui.webcontrols.dropdownlist
        protected   withevents   label1   as   system.web.ui.webcontrols.label
        protected   withevents   textbox2   as   system.web.ui.webcontrols.textbox
        protected   withevents   textbox3   as   system.web.ui.webcontrols.textbox
        protected   withevents   textbox4   as   system.web.ui.webcontrols.textbox
        protected   withevents   textbox6   as   system.web.ui.webcontrols.textbox
        protected   withevents   textbox7   as   system.web.ui.webcontrols.textbox
        protected   withevents   textbox8   as   system.web.ui.webcontrols.textbox
        protected   withevents   label2   as   system.web.ui.webcontrols.label
        protected   withevents   label3   as   system.web.ui.webcontrols.label
        protected   withevents   label4   as   system.web.ui.webcontrols.label
        protected   withevents   label6   as   system.web.ui.webcontrols.label
        protected   withevents   label7   as   system.web.ui.webcontrols.label
        protected   withevents   label8   as   system.web.ui.webcontrols.label
        protected   withevents   label9   as   system.web.ui.webcontrols.label
        protected   withevents   label10   as   system.web.ui.webcontrols.label
        protected   withevents   form1   as   system.web.ui.htmlcontrols.htmlform
        protected   withevents   textbox1   as   system.web.ui.webcontrols.textbox

        '注意:   以下占位符声明是   web   窗体设计器所必需的。
        '不要删除或移动它。
        private   designerplaceholderdeclaration   as   system.object

        private   sub   page_init(byval   sender   as   system.object,   byval   e   as   system.eventargs)   handles   mybase.init
                'codegen:   此方法调用是   web   窗体设计器所必需的
                '不要使用代码编辑器修改它。
                initializecomponent()
        end   sub

#end   region

        private   sub   page_load(byval   sender   as   system.object,   byval   e   as   system.eventargs)   handles   mybase.load
                '在此处放置初始化页的用户代码
                dim   sql   as   string
                sql   =   "select   *   from   tableuserinfo   where   uid= "   &   trim(session( "user "))
                dim   connstr   as   string   =   "server=tse-d2b6bf793dd;uid=sa;pwd=;database=correspondence "
                dim   myconn   as   new   sqlconnection(connstr)
                dim   da   as   new   sqldataadapter(sql,   myconn)
                dim   ds   as   new   dataset
                da.fill(ds,   "tableuserinfo ")
                textbox1.text   =   ds.tables( "tableuserinfo ").rows(0)( "name ")
                textbox2.text   =   ds.tables( "tableuserinfo ").rows(0)( "email ")
                textbox3.text   =   ds.tables( "tableuserinfo ").rows(0)( "mobile ")
                textbox4.text   =   ds.tables( "tableuserinfo ").rows(0)( "uid ")
                textbox6.text   =   ds.tables( "tableuserinfo ").rows(0)( "address ")
                dropdownlist1.selecteditem.text   =   ds.tables( "tableuserinfo ").rows(0)( "gender ")
                textbox7.text   =   ds.tables( "tableuserinfo ").rows(0)( "postcode ")
                textbox8.text   =   ds.tables( "tableuserinfo ").rows(0)( "telephone ")

        end   sub

        private   sub   button1_click(byval   sender   as   system.object,   byval   e   as   system.eventargs)   handles   button1.click
                dim   str   as   string
                '   dim   passstr   as   string
                dim   litem   as   listitem
                '   passstr   =   trim(cstr(text2.text))
                '   passagin   =   trim(cstr(text3.text))
                str   =   " ' "   &   textbox4.text   &   " ' "
                dim   sql   as   string
                sql   =   "select   *   from   tableuserinfo   where   uid= "   &   trim(session( "user "))
                dim   connstr   as   string   =   "server=tse-d2b6bf793dd;uid=sa;pwd=;database=correspondence "
                dim   myconn   as   new   sqlconnection(connstr)
                dim   da   as   new   sqldataadapter(sql,   myconn)
                dim   ds   as   new   dataset
                da.fill(ds,   "tableuserinfo ")
                dim   dacomm   as   sqlclient.sqlcommandbuilder   =   new   sqlclient.sqlcommandbuilder(da)
                ds.tables( "tableuserinfo ").rows(0)( "name ")   =   trim(textbox1.text)
                ds.tables( "tableuserinfo ").rows(0)( "email ")   =   trim(textbox2.text)
                ds.tables( "tableuserinfo ").rows(0)( "mobile ")   =   trim(textbox3.text)
                ds.tables( "tableuserinfo ").rows(0)( "uid ")   =   trim(textbox4.text)
                ds.tables( "tableuserinfo ").rows(0)( "address ")   =   trim(textbox6.text)
                ds.tables( "tableuserinfo ").rows(0)( "gender ")   =   trim(dropdownlist1.selecteditem.text)

                ds.tables( "tableuserinfo ").rows(0)( "postcode ")   =   trim(textbox7.text)
                ds.tables( "tableuserinfo ").rows(0)( "telephone ")   =   trim(textbox8.text)


                da.updatecommand   =   dacomm.getupdatecommand
                da.update(ds,   "tableuserinfo ")
                session( "xstr ")   =   "用户修改成功 "
                response.redirect( "welcome.aspx ")

        end   sub
end   class
发表于:2007-06-12 21:39:161楼 得分:0
但是另一个页面改密码却可以....
imports   system.data
imports   system.data.sqlclient
imports   system.data.oledb
public   class   edit
        inherits   system.web.ui.page

#region   "   web   窗体设计器生成的代码   "

        '该调用是   web   窗体设计器所必需的。
        <system.diagnostics.debuggerstepthrough()>   private   sub   initializecomponent()

        end   sub
        protected   withevents   textbox1   as   system.web.ui.webcontrols.textbox
        protected   withevents   label4   as   system.web.ui.webcontrols.label
        protected   withevents   label3   as   system.web.ui.webcontrols.label
        protected   withevents   label2   as   system.web.ui.webcontrols.label
        protected   withevents   label1   as   system.web.ui.webcontrols.label
        protected   withevents   textbox2   as   system.web.ui.webcontrols.textbox
        protected   withevents   textbox3   as   system.web.ui.webcontrols.textbox
        protected   withevents   button1   as   system.web.ui.webcontrols.button

        '注意:   以下占位符声明是   web   窗体设计器所必需的。
        '不要删除或移动它。
        private   designerplaceholderdeclaration   as   system.object

        private   sub   page_init(byval   sender   as   system.object,   byval   e   as   system.eventargs)   handles   mybase.init
                'codegen:   此方法调用是   web   窗体设计器所必需的
                '不要使用代码编辑器修改它。
                initializecomponent()
        end   sub

#end   region

        private   sub   page_load(byval   sender   as   system.object,   byval   e   as   system.eventargs)   handles   mybase.load
                dim   sql   as   string
                sql   =   "select   *   from   tableuser   where   userid= "   &   session( "reg ")
                dim   connstr   as   string   =   "server=tse-d2b6bf793dd;uid=sa;pwd=;database=correspondence "
                dim   myconn   as   new   sqlconnection(connstr)
                dim   da   as   new   sqldataadapter(sql,   myconn)
                dim   ds   as   new   dataset
                da.fill(ds,   "tableuser ")
                textbox1.text   =   ds.tables( "tableuser ").rows(0)( "userid ")
                '在此处放置初始化页的用户代码
        end   sub

        private   sub   button1_click(byval   sender   as   system.object,   byval   e   as   system.eventargs)   handles   button1.click
                dim   str   as   string
                dim   passstr   as   string
                dim   passagin   as   string
                dim   litem   as   listitem
                passstr   =   trim(cstr(textbox2.text))
                passagin   =   trim(cstr(textbox3.text))
                str   =   " ' "   &   textbox1.text   &   " ' "
                if   passstr   <>   passagin   then
                        response.write( "错误,两次密码输入不相同! ")
                else

                        dim   sql   as   string
                        sql   =   "select   *   from   tableuser   where   userid= "   &   session( "reg ")
                        dim   connstr   as   string   =   "server=tse-d2b6bf793dd;uid=sa;pwd=;database=correspondence "
                        dim   myconn   as   new   sqlconnection(connstr)
                        dim   da   as   new   sqldataadapter(sql,   myconn)
                        dim   ds   as   new   dataset
                        da.fill(ds,   "tableuser ")
                        dim   dacomm   as   sqlclient.sqlcommandbuilder   =   new   sqlclient.sqlcommandbuilder(da)
                        ds.tables( "tableuser ").rows(0)( "userid ")   =   trim(textbox1.text)
                        ds.tables( "tableuser ").rows(0)( "password ")   =   trim(textbox2.text)
                        da.updatecommand   =   dacomm.getupdatecommand
                        da.update(ds,   "tableuser ")
                        session( "xstr ")   =   "用户修改成功 "
                        response.redirect( "welcome.aspx ")
                end   if
        end   sub
end   class
发表于:2007-06-13 08:07:432楼 得分:0
是不是有错误?是不是update的数据的格式不正确?
发表于:2007-06-13 08:34:563楼 得分:0
说出你的错误提示,否则无法帮你
发表于:2007-06-13 10:26:354楼 得分:0
没报错....正常运行

就是不更新....


快速检索

最新资讯
热门点击