access数据丢失

zf815190 2009-07-10 11:02:09
我用vb.net 连接access数据库,明明在程序里操作增加或删除了数据,这时候打开数据库,操作是生效了的,可是,重新一运行程序,数据库又会恢复到没有操作以前的状态,很古怪的问题,大家帮帮忙啊!
附:
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
Dim DBFile As String = Application.StartupPath & "\data.mdb"
Dim strDBCnn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & DBFile & ";Mode=Share Deny None;"

Dim cmdExecuteSQL As OleDbCommand
Dim cnnExecuteSQL As OleDbConnection


Dim cb As OleDbCommandBuilder
cnnExecuteSQL = New OleDbConnection() '打开数据库
With cnnExecuteSQL
.ConnectionString = strDBCnn
.Open()
End With

cmdExecuteSQL = New OleDbCommand()
With cmdExecuteSQL
.Connection = cnnExecuteSQL
.CommandType = CommandType.Text
End With

Dim strsql As String = "select * from data order by 编号"
Dim mdata As New DataSet
Using adar As OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(strsql, cnnExecuteSQL)

cb = New System.Data.OleDb.OleDbCommandBuilder(adar)
adar.Fill(mdata, "data")

Dim newRow As DataRow = mdata.Tables(0).NewRow

newRow("编号") = TextBox2.Text
newRow("姓名") = TextBox5.Text
newRow("卡号") = TextBox3.Text
newRow("部门") = TextBox4.Text
mdata.Tables(0).Rows.Add(newRow)
adar.Update(mdata.Tables(0))


End Using
Dim cs As CellStyle = _flex.Styles.Add("bool") '定义一个单元格格式
cs.DataType = GetType(Boolean)
cs.ImageAlign = ImageAlignEnum.CenterCenter

Dim rg As CellRange

'显示到界面
With _flex
rg = .GetCellRange(.Rows.Count - 2, 0)
rg.Style = .Styles("bool")
.Rows.Count = .Rows.Count + 1
_flex(.Rows.Count - 2, 1) = TextBox2.Text
_flex(.Rows.Count - 2, 2) = TextBox5.Text
_flex(.Rows.Count - 2, 3) = TextBox3.Text
_flex(.Rows.Count - 2, 4) = TextBox4.Text

End With

MsgBox("添加成功!")
End Sub
...全文
66 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zf815190 2009-07-10
  • 打赏
  • 举报
回复
嗯嗯,就是这个问题,谢谢哦
古今多少事 2009-07-10
  • 打赏
  • 举报
回复
在资源管理器窗口右击数据库选属性-复制到输出目录-如果较新则复制试试。
zf815190 2009-07-10
  • 打赏
  • 举报
回复
有知道的朋友,帮帮忙哦
zf815190 2009-07-10
  • 打赏
  • 举报
回复
另一种方式,就算我在数据库里手动添加了数据,用程序打开以后,再打开第二次,数据库又被恢复到没有添加以前了,晕死了。。
Dim dt As New DataTable()
Dim rs As String = "select * from Data"
Dim conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Application.StartupPath & "\data.mdb;Mode=Share Deny None;"
Dim da As New OleDb.OleDbDataAdapter(rs, conn)
da.Fill(dt)

'.DataSource = dt

'make ProductName column too narrow to fit the text

Dim cs As CellStyle = .Styles.Add("bool") '定义一个单元格格式
cs.DataType = GetType(Boolean)
cs.ImageAlign = ImageAlignEnum.CenterCenter

Dim rg As CellRange
Dim x As Integer
For x = 1 To dt.Rows.Count - 1
_flex.Rows.Count = _flex.Rows.Count + 1
rg = .GetCellRange(x, 0)
rg.Style = .Styles("bool")
_flex(x, 1) = dt.Rows(x).Item(0).ToString
_flex(x, 2) = dt.Rows(x).Item(1).ToString
_flex(x, 3) = dt.Rows(x).Item(2).ToString
_flex(x, 4) = dt.Rows(x).Item(3).ToString
Next

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧