Help importing Excel spreadsheet data

zaza123

Member
Joined
Jul 18, 2011
Messages
6
Programming Experience
Beginner
I need help to create a table so, when i import data from microsoft excel, the data will go to the table on the form which is similar to the table in microsoft excel. Then from the form, if column 1is equal to column 2, messagebox = (NE), ELSE Messagebox = (E).​
 
What aspect of this task are you having trouble with? Specific code examples or areas you are having trouble in can give you a much better chance of getting help. Also, please explain EXACTLY what you are looking to accomplish and we can tell you the best way to go about it. You are importing Excel into what type of database? Where are you looking to create this table? What type of form are you using and what does it do? etc, etc..
 
Ok first i need data on the excel sheet to be transfered on to the form of vb.net. Vb.Net will have a table identical to the microsoft excel sheet. On the Vb. net, It will do all the calculations and then ill export it back to the excel sheet and do the changes. There is also a check box which will allow me to filter stuff from the excel sheet.
 
Here is what i have done

If there is any error or any way u can improve it pls help me!!!i wanna learn if there is a shorter way
Thx alot
 

Attachments

  • Automate.zip
    26.5 KB · Views: 30
Last edited by a moderator:
Take a datagridview and set its datasource to the table at 0 index of the returned dataset.

this code is for excell 2003 won't work with 2007

VB.NET:
Public Function ReadExcel(filePath As [String], sheetName As [String]) As DataSet
	Try
		sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Convert.ToString(filePath) & ";" & "Extended Properties=Excel 8.0;"

		objConn = New System.Data.OleDb.OleDbConnection(sConnectionString)

		objConn.Open()

		tran = objConn.BeginTransaction()

		Dim objCmdSelect As New System.Data.OleDb.OleDbCommand("SELECT * FROM [" & Convert.ToString(sheetName) & "$]", objConn)
		objCmdSelect.Transaction = tran
		Dim objAdapter1 As New System.Data.OleDb.OleDbDataAdapter()

		objAdapter1.SelectCommand = objCmdSelect

		Dim objDataset1 As New DataSet()
		objAdapter1.Fill(objDataset1)
		tran.Commit()
		objConn.Close()

		Return objDataset1
	Catch
		tran.Rollback()
		Throw
	Finally
		objConn.Close()
	End Try

End Function
 
Last edited by a moderator:
Back
Top