|
Hi.
Last week I posted a question regarding reading Excel file and loading it into the DataGrid.
I didn't get any useful response back so please forgive me for posting this second time.
I'm sure someone had the same problem I have.
I have 3 columns in Excel. One of the columns (User Id) has text data (like: User 1) or a number data (like: 12345). My code works and doesn't throw any error but for some reason it only extracts text data. The numbers are missing and I'm not sure why. I've tried to foramt that columnt to TEXT only but it doesn't help. Just to be sure I looped through DataSet to make sure the values are there and of course they weren't.
Here's the code that reads Excel and loads data into DataGrid. Please help.
Thank you.
Try<br />
'Create DataSet and DataAdapter<br />
ds = New System.Data.DataSet<br />
da = New System.Data.OleDb.OleDbDataAdapter<br />
<br />
'Establish connection<br />
con = New System.Data.OleDb.OleDbConnection( _<br />
"provider=Microsoft.Jet.OLEDB.4.0; " & _<br />
"data source=" & Session("ExcelFilePath").ToString() & "; " & _<br />
"Extended Properties=Excel 8.0")<br />
<br />
'Create command<br />
cmdSelectExcel = New System.Data.OleDb.OleDbCommand("SELECT * FROM [Sheet1$] ORDER BY Company", con)<br />
<br />
'Open connection<br />
con.Open()<br />
<br />
'Exectue command through adapter<br />
da.SelectCommand = cmdSelectExcel<br />
da.Fill(ds, "[Sheet1$]")<br />
<br />
'Assign DataSourse of the DataGrid and bind it<br />
dg.DataSource = ds.Tables(0).DefaultView<br />
dg.DataBind()<br />
<br />
'Close Connection<br />
con.Close()<br />
Catch ex As Exception<br />
'Display error message<br />
lblError.Text = "Error: " & ex.ToString()<br />
lblError.Visible = True<br />
End Try
|
|
|
|
|
Do you have the facility on Access to fire a SQL command at the database. You can do this in MSSQL 2005 and it will show you the results as they would appear.
|
|
|
|
|
Not sure what you mean. I'm trying to read Excel file using OleDb.
|
|
|
|
|
I am curently using MSSQL server 2005. An option to this is MS SQL Server Management Studio which allows you to fire SQL queries straight at the database and then shows you the returned results. I often use this feature to test SQL prior to placing it in the code. Is there a similar feature in Acess that would allows this. If there is, and you perform this and retrieve the details with the numbers requested then you can be sure the problem is with the Oledbadapter or something in your code. Rather than the SQL or access.
Hope this makes more sense.
|
|
|
|
|
Thank you. I know that the problem is with OldeDb. Like I've mentioned before it doesn't retreive values from Excel, they are just empty. In my research I found out that when you use OldeDb to extract data from Excel it uses first column's format, which is text in my example. I just thought there's a way around it.
Thank you again. If you hear anything let me know. And if I find something out I'll pst it here.
Alex.
|
|
|
|
|
OK. I figured it out with the help of a samrt man of course.
Here's the code and it will work. I hope that I can save some time to others if they need to do the same thing I do now.
Enjoy.
Try<br />
'Create DataSet and DataAdapter<br />
ds = New System.Data.DataSet<br />
da = New System.Data.OleDb.OleDbDataAdapter<br />
<br />
con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Session("ExcelFilePath").ToString() & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1;MaxScanRows=0""")<br />
<br />
'Create command<br />
cmdSelectExcel = New System.Data.OleDb.OleDbCommand("SELECT c.[Company], c.[Journal Entry], c.[Vendor] FROM [Sheet1$] AS c ORDER BY c.[Company]", con)<br />
<br />
'Open connection<br />
con.Open()<br />
<br />
'Exectue command through adapter<br />
da.SelectCommand = cmdSelectExcel<br />
da.Fill(ds, "Company")<br />
<br />
'Assign DataSourse of the DataGrid and bind it<br />
dg.DataSource = ds.Tables(0).DefaultView<br />
dg.DataBind()<br />
<br />
'Close Connection<br />
con.Close()<br />
Catch ex As Exception<br />
'Display error message<br />
lblError.Text = "Error: " & ex.ToString()<br />
lblError.Visible = True<br />
End Try
|
|
|
|
|
I'm trying to find a definitive answer to this question:
How many users are allowed to view web reports on Crystal Reports 11 developer edition?
I keep getting different answers. Business Objects told me there was no limit however I keep reading online that there is in fact a limit.
I'm developing a website for our client that needs to generate PDF/excel reports for each of their sales reps(meaning each of their 1100 sales reps needs to have the ability to go onto the website and view their report).
The website will be located on one of our company servers but obviously, outside of our firewall.
Can I use crystal for this task of handling 1100 sales reps or is there a limit to the number of users who can use this? If not, can anyone recomend a better alternative?
Thanks.
-Goalie35
|
|
|
|
|
Hi May be this is not the appropriate place but still believe it will yield something. Pls guide me to a starting link for web promotion on search engine and marketing the web site for generating revenue.
Many thanks
Don't Quit
|
|
|
|
|
web promotion is very - very good and easy work for web site promotion if you want to gruid properly read on google search engine.Its make easy for you.
Pavan Pareta
|
|
|
|
|
Hi all,
can any one tell me the difference b/w DataGrid & Gridview webserver controls?
is there any site which explains me about .NET 2.0 server controls other than Microsoft.com?
Thanks,
Rahi Sharma
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
The GridView replaces the DataGrid in ASP.Net 2.0. I'm guessing they changed the name because of the great deal or new funcionality built in to it since version 1.1. EG Sorting
|
|
|
|
|
I just had my most embarasing moment when I realised that I cant link to a website from an event handler.
Can you show me the code to transfer to(maybe codeproject.com) from an eventhandler using VB.net in an ASP.NET page
Soon to be famous black south african programmer
|
|
|
|
|
Response.Redirect("http://www.codeproject.com")
|
|
|
|
|
Hi there.......
I used validation controls in my aspx applicaion, in local machine it's working fine. If i uploaded in remote server, it is showing error..
If i use this,
means, in remote server validation controls are working fine, but button click event was not generated.........
Please help me.....
Thks n Advance
Sam.M
|
|
|
|
|
pls provide full path of our javascript file like
Keep Smiling !!! Tomorrow Never Die
Parwej Ahamad
g_parwez@rediffmail.com
|
|
|
|
|
Hi,
I am not able to take the setup of my web application.I have right clicked on the solution and added new project. selected the primary output,content files etc.
Every thing is getting compiled when I rebuild the solution but the content files are not getting added.
I could only see the bin directory.
Please help..
Regards,
Sivaprasad
|
|
|
|
|
Hi,
Can anyone suggest a free to use web service for a test bed application?
Something like a weather forecast service..
Any thought?
Kevin
|
|
|
|
|
how can i create a proxy of ma web service
bia
|
|
|
|
|
|
Hi All,
We can use server.execute() to execute child webpages and get the response.
Suppose that we have a page on http://www.abc.com/default.asp;
Now How can I execute the url and get the whole response including javascript executions.
I need to do using ASP.NET ,C#
Please help me to solve the problem.
Thanks in advance.
|
|
|
|
|
you can open the url using httpwebRequest and httpwebResponse but it will not run javascript for that you have load html page in the memory so that it allow the javascript to run .
Reply What you have to do (read data coming from java script function ?)
|
|
|
|
|
Hi,
Yes I have used HttpwebRequest class for my work.But Javascript functions are not executing.
Suppose that in the the Response Page In side the Tag following javascript consists:-
How can get complete response page with executing Javascripts?
Please kindly help me.
Thanks in advance.
|
|
|
|
|
You can do that by getting whole HTML page into memory
Use microsoft.mshtml.dll and AxSHDocVw.dll
string URL="http://www.Google.co.in";
object oMissing = null;
HTMLDocumentClass objects=new HTMLDocumentClass();
axWebBrowser1.Navigate(URL,ref oMissing,ref oMissing,ref oMissing,ref oMissing);
while(axWebBrowser1.Busy)
{
Application.DoEvents();
}
objects=(HTMLDocumentClass)axWebBrowser1.Document;
If you are using Windows application then it works fine but don't know for web application
Best of luck
Sandeep
|
|
|
|
|
Hi,
I am populating a regular datagrid with field data. One of those fields shows a "Severity" rating. There are 3 "Severity" ratings:
1 - Red
2 - Amber
3 - Green
Instead of displaying "Red ", "Amber " or "Green " in the column of the datagrid, I would like to display a different image for each. ie. Green Circle for "Green ", Orange Circle for "Amber " and a Red Circle for "Red ".
I was informed that I have to use the ItemDataBound Event for this, but I don't know how. Please Help!
Thank you.
|
|
|
|
|
Yes that is correct you can use OnItemDataBound event. This event gets fired for each row of the datagrid and there in that event you can check what you need to display(depending upon your condition).
Best Regards,
Apurva Kaushal
|
|
|
|