excel datagrid上传后保存在数据集中 [英] Save in dataset after excel datagrid upload

查看:82
本文介绍了excel datagrid上传后保存在数据集中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我是新代码área所以我有一个新手问题。



所以,我有一个多用户可以在一个模板中创建请求的项目。

该模板链接到一个链接到云sql db的数据集。

到目前为止一切正常。

现在,我想用户可以通过excel上传请求,所以我有另一个excel上传模板。

以下代码有效,我可以看到所有请求在myDatagridview中,问题是我无法将其保存在我的数据集中,也无法从云端sql DB中保存。





Hi guys.

Im new in code área so i got a newbie question.

So, i have project where multiusers can create requests in 1 template.
That templete is linked to a dataset which is linked to a cloud sql db.
Everything ok so far.
Now, i would like that the user can upload requests by excel so i have another template for excel upload.
The code below works and i can see all the requests in myDatagridview the problem is that im unable to save it in my Dataset and also on the cloud sql DB from here .


Private Sub ExcelUploadButton_Click(sender As Object, e As EventArgs) Handles ExcelUploadButton.Click

Try

            Dim MyConnection As String = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Temp\My Project\Upload\UploadFile.xls;" & _
                "Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1""")

            Dim conn As New OleDbConnection(MyConnection)

            Dim cmdselect As New OleDbCommand("select * from [My Sheet Name$]", conn)

            Dim adapter As New OleDbDataAdapter

            adapter.SelectCommand = cmdselect

            Dim ds As New DataSet

            adapter.Fill(ds)

            MyDataGridView.DataSource = ds.Tables(0)

            conn.Close()

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

 End Sub





因为在另一个模板上,每次都是我需要填充不同的数据(或保存)我调用适配器我试图使用excel上传按钮上的代码保存,但显然没有工作。







Since that on the other template, for each time that i need to populate with diferent data (or save it) i call the adapter i tried to use the code on the excel upload button to save, but as obviously didn work.


 Private Sub ButtonSaveUpload_Click(sender As Object, e As EventArgs) Handles ButtonSaveUpload.Click

   Me.Validate()

   Me.MyBindingSource.EndEdit()

   Me.TableAdapterManager.UpdateAll(Me.MyDataSet)

End Sub



我该怎么办?

提前谢谢。


What can i do?
Thanks in advance.

推荐答案

,conn)

Dim adapter As OleDbDataAdapter

adapter.SelectCommand = cmdselect

Dim ds 作为 DataSet

adapter.Fill(ds)

MyDataGridView.DataSource = ds.T ables( 0

conn.Close()

Catch ex As 异常

MsgBox(ex.Message)

结束 尝试

结束 Sub
", conn) Dim adapter As New OleDbDataAdapter adapter.SelectCommand = cmdselect Dim ds As New DataSet adapter.Fill(ds) MyDataGridView.DataSource = ds.Tables(0) conn.Close() Catch ex As Exception MsgBox(ex.Message) End Try End Sub





因为在另一个模板上,每次我需要填充不同的数据(或保存)我调用适配器我试图使用excel上传按钮上的代码保存,但显然没有工作。







Since that on the other template, for each time that i need to populate with diferent data (or save it) i call the adapter i tried to use the code on the excel upload button to save, but as obviously didn work.


 Private Sub ButtonSaveUpload_Click(sender As Object, e As EventArgs) Handles ButtonSaveUpload.Click

   Me.Validate()

   Me.MyBindingSource.EndEdit()

   Me.TableAdapterManager.UpdateAll(Me.MyDataSet)

End Sub



我该怎么办?

提前谢谢。


What can i do?
Thanks in advance.


无法像常规数据库表一样更新Excel文件没有主键和其他相关的基础设施。



查看免费的SaveToDB Express插件:

http://www.savetodb.com/help4/savetodb-getting-started.htm [ ^ ]



它可以帮助您连接云数据库并保存ed使用Microsoft Excel返回数据。
It is not possible to update Excel files like regular database tables as they do not have primary keys and other related infrastructure.

Look at the free SaveToDB Express add-in:
http://www.savetodb.com/help4/savetodb-getting-started.htm[^]

It can help you to connect the cloud database and save the edited data back using Microsoft Excel.


这篇关于excel datagrid上传后保存在数据集中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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