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



数据库插入问题


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


数据库插入问题
发表于:2008-02-19 15:07:41 楼主
我用odbcconnection连接的数据库怎样进行插入操作啊,我写的下面的代码,不能成功插入,单独运行sql语句没有问题的,而却数据库也能连接成功的,那位高手帮帮忙啊

public   sub   btclick(byval   str   as   string)
                select   case   str
                        case   "btn_add"
                                dim   gcompy_cd   as   string
                                dim   gcompy_mei   as   string
                                dim   gcompy_info   as   string
                                dim   gbusuu   as   integer
                                dim   sql   as   string
                                dim   addtime   as   string
                                dim   str1   as   string   =   "dsn=datasoure;uid=yuyanping-pc;pwd=;"
                                dim   cnn   as   odbcconnection   =   new   odbcconnection(str1)
                                dim   cmd   as   odbcdataadapter
                                'dim   dt   as   datatable
                                gcompy_cd   =   me.comb_cmpcd.text
                                gcompy_mei   =   me.txt_cmpmei.text
                                gcompy_info   =   me.txt_cmpinfo.text
                                gbusuu   =   me.txt_busuu.text
                                addtime   =   format(now(),   "yyyy/mm/dd   hh:mm:ss")
                                cnn.open()
                                sql   =   "insert   into   compy_mst(compy_cd,compy_mei,compy_info,busuu,makeymd,updymd)values('"   &   gcompy_cd   &   "','"   &   gcompy_mei   &   "','"   &   gcompy_info   &   "',"   &   gbusuu   &   ",'"   &   addtime   &   "',null)"
                                'cmd   =   new   odbcdataadapter(sql,   cn)
                                dim   mycommand   as   sqlcommand   =   new   sqlcommand(sql,   cnn)
                                'sqlcommand(mycommand   =   new   sqlcommand(sql,   cn))
                                cn.close()

                end   select
        end   sub
发表于:2008-02-19 15:34:431楼 得分:0
你在插入后好像没有保存数据更新哦。
发表于:2008-02-20 09:54:192楼 得分:0
我找到原因了在   sqlcommand(mycommand       =       new       sqlcommand(sql,       cn))的后面加上  
mycommand   =   new   odbccommand(sql,   cnn)
                mycommand.EXECutenonquery()
就可以了
发表于:2008-02-20 09:56:413楼 得分:0
自己解决?接分
发表于:2008-02-20 10:47:534楼 得分:0
我也来接分
发表于:2008-02-20 10:52:015楼 得分:0
他还没有学会怎么给分呢  

大菜鸟     哈哈


快速检索

最新资讯
热门点击