Click here to Skip to main content
15,920,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have two questions in relation to database
How to save a list box in the Access database?
How to save a file in Visual Basic Access database. Grid View is the ability to edit and view the data.

Let's'm grateful source

What I have tried:

How to save a list box in the Access database
Posted
Updated 10-Jan-17 9:34am
Comments
[no name] 10-Jan-17 15:04pm    
"How to save a list box in the Access database?", you don't. You save the data in the listbox to a database.

1 solution

I don't quite understand the question about saving a list box to Access database, but what comes to saving Excel file into a database, it's another thing.

The Excel file is after all a series of bytes so you read the bytes, place the data into a parameter for INSERT or UPDATE statement, open the connection and save the data.

In short the code could look something like
VB
Dim fs As System.IO.FileStream
Dim sr As System.IO.StreamReader

fs = New System.IO.FileStream("c:\path\excelfile", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
sr = New System.IO.StreamReader(fs)
Dim bytes(fs.Length - 1) As Byte
fs.Read(bytes, 0, fs.Length)

Try
   Using connection As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=accessfilename")
      Using command As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand("insert into tablename (columnname) values (?)", connection)
         command.Parameters.Add("@bytes", System.Data.OleDb.OleDbType.Binary, fs.Length).Value = bytes
         connection.Open()
         command.ExecuteNonQuery()
         connection.Close()
      End Using
   End Using
Catch exception As Exception
   ' error handling goes here
End Try
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900