简体   繁体   中英

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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