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



vb.net如何用addnew添加一个记录到数据库中去


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


vb.net如何用addnew添加一个记录到数据库中去[无满意答案结贴,结贴人:shenpq2008]
发表于:2007-09-19 12:32:53 楼主
我的代码如下:
dim   drnew   as   system.data.datarow
                drnew   =   me.out1.express.newrow()
                drnew.item( "id ")   =   me.textbox1.text.trim
                drnew.item( "fcompany ")   =   me.textbox2.text.trim
                drnew.item( "faddress ")   =   me.textbox3.text.trim
                drnew.item( "farea_code ")   =   me.textbox4.text.trim
                drnew.item( "ftel ")   =   me.textbox5.text.trim
                drnew.item( "fname ")   =   me.textbox6.text.trim
  me.out1.express.rows.add(drnew)
                me.sqldataadapter1.update(me.out1,   "express ")
但老是不行!我想换一个方法解决啦
请赐教啊!!无比感激啊!!!!!!
发表于:2007-09-19 14:58:051楼 得分:0
没有报错吗?你没有给dataadapter指定要更新的表!!
发表于:2007-09-19 17:33:312楼 得分:0
帮你顶了。。
发表于:2007-09-19 20:53:423楼 得分:0
me.sqldataadapter1.update(me.out1,   "express ")中的express就是数据库中的表啊
最后一行老是报错!错误信息如下:
未处理的“system.data.sqlclient.sqlexception”类型的异常出现在   system.data.dll   中。其他信息:   系统错误。
请问高手这是怎么回事啊?
有没有其他写法?
如insert   into   (.......)

发表于:2007-09-19 21:04:354楼 得分:0
要添加进去好象还要两句话
好象还要申明个commandbuilder
发表于:2007-09-20 11:40:265楼 得分:0
dim   connstring2   as   string   =   "provider=microsoft.jet.oledb.4.0;   data   source=d:\vimage.mdb "    


dim   cn   as   new   oledb.oledbconnection(connstring2)
                        cn.open()

dim   cmd   as   new   oledb.oledbcommand
                                cmd.connection   =   cn
                                cmd.commandtype   =   commandtype.text
                                cmd.commandtext   =   "insert   into   bom([stytype],[styseq],[description],[fcdate],[lmdate],[memo],[browse])     values   (@stytype,@styseq,@description,@fcdate,@lmdate,@memo,@browse) "

                                'form3.label1.text   =   s

                                cmd.parameters.add( "@stytype ",   oledb.oledbtype.varchar).value   = "123 "
    cmd.parameters.add( "@styseq ",   oledb.oledbtype.varchar).value   =   "123 "
                  cmd.parameters.add( "@description ",   oledb.oledbtype.varchar).value   =   "123 "
                            cmd.parameters.add( "@fcdate ",   oledb.oledbtype.date).value   =   "123 "
                            cmd.parameters.add( "@lmdate ",   oledb.oledbtype.date).value   = "123 "  
                            cmd.parameters.add( "@memo ",   oledb.oledbtype.varchar).value   =   "123 "
                          cmd.parameters.add( "@browse ",   oledb.oledbtype.varbinary).value   =   "123 "

                                cmd.EXECutenonquery()
cn.close()
发表于:2007-09-20 11:41:336楼 得分:0
你試試我的代碼,你改一下數據庫路徑,和字段名就行拉。後面的“123”就是你要加進去的字符串。
发表于:2007-09-20 15:27:057楼 得分:0
大哥啊!我是用你的代码了,把数据库路径和字段名都该了(我用的是sql   server   2000的   数据库)
后面的 "123 "我用textbox1.text.trim代替.但是在
cmd.EXECutenonquery()这行老是错,错误信息如下:
未处理的“system.data.sqlclient.sqlexception”类型的异常出现在   system.data.dll   中。
其他信息:   系统错误。
急急急急!!!在线等!!
发表于:2007-09-20 16:15:388楼 得分:0
在from_load中要不要声明数据库要打开呢???
dim   cn   as   sqlconnection   =   new   sqlconnection( "server=dataserver;database=kevin;uid=sa;pwd= ")
                cn.open()......


快速检索

最新资讯
热门点击