简体   繁体   English

如何使用访问数据库VB.net 2010保存我在datagridview中添加的列

[英]How to save the columns which i added in my datagridview using access database VB.net 2010

I'm using this code to add a new column: 我正在使用以下代码添加新列:

DataGridView1.Columns.Add("Test", "TesT")

but after saving and closing the project then I open it again the columns were deleted. 但是在保存并关闭项目后,我再次打开它,删除了列。

The question is how to save the columns to the access database. 问题是如何将列保存到访问数据库。

If your just going to save the values, than you'd have to call them back up in order to fill the grid. 如果您只是要保存这些值,则必须将它们重新命名以填充网格。

Sample code to insert into an access db. 插入到访问数据库的示例代码。

Dim Cmd as New OLEDb.OleDbCommand
Dim oleConn as New OleDb.OleDbConnection
Dim strDataBase as String

strDataBase = "C:\Test.mdb"

'2007 connection string will work for 2003-2007 databases - change to 14.0 for 2010 etc
oleConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strDataBase & ";Jet OLEDB"

Cmd.Connection = oleConn
oleConn.Open()
Cmd.CommandText = "Insert into mytable ( Field1, Field2 ) values ( '" & "some Value" & "', '" & "some value" & "' )"
Cmd.ExcuteNonQuery
oleConn.Close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM