从datagrid更新访问文件 [英] Update access file from datagrid

查看:68
本文介绍了从datagrid更新访问文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看我的编程。我有组合框,其中有所有表格的访问权限

文件。用户选择一个表,内容显示在datagrid中。

用户可以添加,删除或修改某些记录或行。到现在还可以,但是去了

我想更新访问文件,VB发给我错误。有些人可以帮助我

Dim myCnn As New OleDb.OleDbConnection


Dim objDataAdapteur As OleDbDataAdapter


Dim objDataSet作为New Data.DataSet


Dim objDataTable As DataTable


----------------- -------------------------------------------------- ---------

--------------------------------- ------------------------------


Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System .Object,

ByVal e As System.EventArgs)处理ComboBox1.SelectedIndexChanged

myCnn.ConnectionString =" Provider = Microsoft.Jet.OLEDB.4.0;数据来源="

& AccessFile& ""


myCnn.Open()


Dim strSQL As String =" SELECT * FROM [" &安培; TableName& "]"


objDataAdapteur =新OleDb.OleDbDataAdapter(strSQL,myCnn)


Dim objCB As OleDb.OleDbCommandBuilder = New

OleDb.OleDbCommandBuilder(objDataAdapteur)

objDataAdapteur.Fill(objDataSet,TableName)


objDataTable = objDataSet.Tables( TableName)


DataGrid1.SetDataBinding(objDataTable,"")


End Sub


------------------------------------------------- ---------------------------

--------------- -----------------------------------------------


''点击按钮复制访问文件中datagrid的修改


Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理Button1.Click


objDataAdapteur.Update(objDataSet,TableName)


myCnn.Close( )


End Sub

Look my prog. I have combobox where is have all tables names of access
file. The user select one table and the content is show in datagrid. The
user can add, erase or modify some record or row. Until now is ok but went
I want to update access file, VB send me error. Some body can help me
Dim myCnn As New OleDb.OleDbConnection

Dim objDataAdapteur As OleDbDataAdapter

Dim objDataSet As New Data.DataSet

Dim objDataTable As DataTable

----------------------------------------------------------------------------
---------------------------------------------------------------

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

myCnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& AccessFile & ";"

myCnn.Open()

Dim strSQL As String = "SELECT * FROM [" & TableName & "]"

objDataAdapteur = New OleDb.OleDbDataAdapter(strSQL, myCnn)

Dim objCB As OleDb.OleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(objDataAdapteur)

objDataAdapteur.Fill(objDataSet, TableName)

objDataTable = objDataSet.Tables(TableName)

DataGrid1.SetDataBinding(objDataTable, "")

End Sub

----------------------------------------------------------------------------
--------------------------------------------------------------

''Click on button to copy modify on datagrid in access file

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

objDataAdapteur.Update(objDataSet, TableName)

myCnn.Close()

End Sub

推荐答案

*& QUOT; facicad" < ca*@norclair.com> scripsit:
* "facicad" <ca*@norclair.com> scripsit:
我有组合框,其中有所有表格的访问权限文件。用户选择一个表,内容显示在datagrid中。
用户可以添加,删除或修改某些记录或行。直到现在还可以,但是去了
我想更新访问文件,VB发给我错误。
I have combobox where is have all tables names of access
file. The user select one table and the content is show in datagrid. The
user can add, erase or modify some record or row. Until now is ok but went
I want to update access file, VB send me error.




什么错误?


对于数据(基础)相关问题,请尝试使用此组:


< URL:news://news.microsoft.com/microsoft.public.dotnet.framework .adonet>


网络界面:


< URL:http://msdn.microsoft.com/newsgroups/?dg = microsoft .public.dotnet.framework.adonet>


-

Herfried K. Wagner [MVP]

< URL: http://dotnet.mvps.org/>



What error?

For data(base) related questions, give this group a try:

<URL:news://news.microsoft.com/microsoft.public.dotnet.framework.adonet>

Web interface:

<URL:http://msdn.microsoft.com/newsgroups/?dg=microsoft.public.dotnet.framework.adonet>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


>对于数据(基础)相关问题,请尝试使用此组:
> For data(base) related questions, give this group a try:

< URL:news://news.microsoft.com/microsoft.public.dotnet.framework.adonet>

<URL:news://news.microsoft.com/microsoft.public.dotnet.framework.adonet>




但是当它是关于Win32时,SQLserver或VB6可以随意使用这个

新闻组。


你得到Herfried的回答。 K.瓦格纳在这里。


:-(


Cor



However when it is about Win32, SQLserver or VB6 feel free to use this
newsgroup.

You than get your answers from Herfried. K. Wagner here.

:-(

Cor


Hi Faci ,


在没有conn.open和conn.close的程序中尝试。


但是因为它是访问权限而且对我来说是首选要打开和关闭

只有一次,你可以在表单的load_event中打开连接,然后在表单的close_event中关闭它。


但是首先尝试删除这两个,数据适配器打开并且

在没有打开之前自己关闭它。


我希望这有帮助吗?


Cor

Hi Faci,

Try it in your program without the conn.open and the conn.close.

Howeverr because it is access and for me prefered to open and close that
only one time, you can open the connection in the load_event of the form and
close it in the close_event of the form.

However try it first with removing those two, the dataadapter opens and
closes it himself when there has no open been done before.

I hope this helps?

Cor


这篇关于从datagrid更新访问文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆