Using Visual Web Developer 2005 and VB, I have created a web form page with a datagrid that shows the data which is stored in an SQL database Table. Everything shows perfectly but it requires the data to already be in the database. Right now, I am exporting the data as a csv file, clearing the data out of the table in the database, and manually importing the csv file. What I would like is to have an Upload procedure that will automatically clear the table and input the new data into that same table without any extra measures by the user.
I created a FileUpload procedure (FileUpload1) which allows the user to browse to the file they want. I have set up a string that holds the location of that file (fi as string). I also have a Import button (btnImport) which is where I need to write the code which will take the csv file in the above location (fi) and save it to the database table I have set up. I basically want to be able to skip having to go to the SQL Server Manager and import the csv into the table whenever they need it. I also want there to be no interaction for this part by the user other than choosing the file to import.
Amy help would be greatly appreciated.
You should be able to connect directly to the csv file with and OleDbConnection and use a OleDbDataAdapter.Fill() to fill a DataSet. Once you have the dataset you can bind directly to the datagrid. Checkwww.connectionstrings.com for the correct connection string. You will need to dynamically insert the path to the file into the connection string.
-David
No comments:
Post a Comment