标题:vb.net 向数据库插入记录不行为什么?
只看楼主
jeck001
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-3-10
 问题点数:0 回复次数:1 
vb.net 向数据库插入记录不行为什么?
Imports System.Data.OleDb
Public Class main
 Private Sub main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       Static cn As OleDbConnection
        Static da As OleDbDataAdapter
        Static ds As DataSet
        
        Static cnStr As String
        cnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\tools\MyFile\Assessment\Assessment\data.mdb;Persist Security Info=False"

        cn = New OleDbConnection(cnStr)
        Dim sql As String
        sql = "select * from User_tbl"
        da = New OleDbDataAdapter(sql, cn)
        ds = New DataSet
        da.Fill(ds, "User_tbl")
        DataGridView1.DataSource = ds.Tables(0)


        Static Name As String
        Static pwd As String
        Name = "sdfs"
        pwd = "sdfs"


        'cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\tools\MyFile\Assessment\Assessment\data.mdb;Persist Security Info=False")
        cn.Open()
        Static sd As String
        sd = "insert into User_tbl (ID,name,pwd) values('" & "','" & Name & "','" & pwd & "'')"
        Static cm = New OleDbCommand(sd, cn)
        'cm.ExecuteNonQuery()

        cn.Close()
        MessageBox.Show("保存成功!!!")

    End Sub

End Class
这是代码?
搜索更多相关主题的帖子: Object 数据库 False 记录 
2014-03-10 15:45
tangyixp
Rank: 1
等 级:新手上路
帖 子:4
专家分:5
注 册:2014-3-11
得分:0 
把数据插入语句写到try中,
Catch ex As Exception
 MsgBox(ex.ToString)看看是什么错误提示。
2014-03-14 18:52



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-428265-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018997 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved