and how can we retrive a string from an excel database in the dataset?
Try Dim fBrowse As New OpenFileDialog With fBrowse .Filter = "Excel files(*.xls)|*.xls|All files (*.*)|*.*" .FilterIndex = 1 .Title = "Import data from Excel file" End With If fBrowse.ShowDialog() = Windows.Forms.DialogResult.OK Then Dim fname As String fname = fBrowse.FileName Dim MyConnection As System.Data.OleDb.OleDbConnection Dim DtSet As System.Data.DataSet Dim MyCommand As System.Data.OleDb.OleDbDataAdapter MyConnection = New System.Data.OleDb.OleDbConnection _ ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fname & ";" & "Extended Properties=""Excel 8.0;HDR=NO;IMEX=1""") MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from[Sheet1$]", MyConnection) MyCommand.TableMappings.Add("Table", "TestTable") DtSet = New System.Data.DataSet '' Here is dataset with all the data from Excel file. MyCommand.Fill(DtSet) MyConnection.Close() End If Catch ex As Exception MessageBox.Show(ex.ToString) End Try
Edited 5 Years Ago by Pgmer: n/a
dbprovider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 5.0;"
dbsource = "Data Source = C:\Documents and Settings\aditya\My Documents\user2.XLS"
con.ConnectionString = dbprovider & dbsource
SQL = "SELECT * FROM [products$]"
Cmd = New OleDb.OleDbCommand(SQL, con)
objCmd = New OleDb.OleDbCommand(SQL, con)
da = New OleDb.OleDbDataAdapter(SQL, con)
'MsgBox("hello connection is opened")
DataGrid1.DataSource = ds
i have used this code and its working good so far but its not able to retrive a string into the datagrid, its giving a value as null, where the text,"hello" is present in the excel sheet.
In which column the text is? And can you provide the sample excel file? It should read whaterver is there in excel file.
Why do you have these:
objCmd = New OleDb.OleDbCommand(SQL, con) objCmd.ExecuteNonQuery()
SQL var does contain a query.
And I don't think you are going to need this:
Cmd = New OleDb.OleDbCommand(SQL, con) either.
Edited 5 Years Ago by adam_k: n/a
Is it an actual database (regularly definied rows and columns) or is it a spreadsheet with varying fields depending on the row? In one case you CAN access the data using ADO (or whatever MS calls it now) and recordsets, etc. If not then you can access the rown and columns using an Excel object that can be created within VB. If it's the second case we can also give you sample code.
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.
This is the result of previous question answered :
code for the listbox - datagridview interaction
At the top of the code ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...