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



我想向access数据库中插入一行代码如下,但总是不成功,本人是初学者请教,谢过!


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


我想向access数据库中插入一行代码如下,但总是不成功,本人是初学者请教,谢过!
发表于:2007-02-06 22:15:13 楼主
private   sub   button1_click(byval   sender   as   system.object,   byval   e   as   system.eventargs)   handles   button1.click

                dim   connectionstring   as   string   =   "provider=microsoft.jet.oledb.4.0;data   source= "   &   application.startuppath   &   "\users.mdb "
                dim   getallsql   as   string   =   "select   *   from   users "
                dim   connection   as   new   oledbconnection(connectionstring)
                dim   adapter   as   new   oledbdataadapter(getallsql,   connection)
                dim   cb_adapter   as   new   oledbcommandbuilder(adapter)
                dim   ds   as   new   dataset
                connection.open()
                adapter.fill(ds,   "users ")
                datagrid1.datasource   =   ds
                datagrid1.datamember   =   "users "
                dim   dr   as   datarow   =   ds.tables( "users ").newrow()
                dr.item( "id ")   =   7         ' ' '主键
                dr.item( "user_name ")   =   " "
                dr.item( "password ")   =   " "
                dr.item( "real_name ")   =   " "
                dr.item( "tel ")   =   " "
                dr.item( "email ")   =   " "
                dr.item( "submit_date ")   =   "2007-2-5 "

                ds.tables( "users ").rows.add(dr)
                adapter.update(ds,   "users ")


        end   sub

错误提示:未处理的“system.data.oledb.oledbexception”类型的异常出现在   system.data.dll   中。
发表于:2007-02-07 08:18:021楼 得分:0
去掉
      dr.item( "id ")   =   7         ' ' '主键

试一下
发表于:2007-02-07 16:21:412楼 得分:0
其它没什么问题,就按照楼上的试试看吧
发表于:2007-02-12 22:24:053楼 得分:0
谢谢blog


快速检索

最新资讯
热门点击