|
|
You can use the OleDb Managed Data Provider to read an Excel Spreadsheet using ADO.NET and C#
|
|
|
|
|
You can use InterOp service provided by Microsoft using Excel namespace.
namespace for Excel is,
Microsoft.Office.Interop.Excel
|
|
|
|
|
Hi Bhavesh,
Just a gentle suggestion.
This solution needs that you either assumes Office to be installed in the machine or you have to distubute the office libraries along with the Apps.
Please find my last post for this question it sould provide a better and faster solution.
laddie
|
|
|
|
|
TAREQ
Try this
using System.Data.OleDb;
using System.Data;
.
.
//I am not sure giving url in the filename will work.Please check it
OleDbConnection oleConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+fileName+@";Extended Properties=""Excel 8.0;HDR=YES""");
oleConenction.Open();
OleDbCommand cmd= new OleDbCommand("select * from [Sheet1$]",oleConnection);
OleDbDataReader read = cmd.ExecuteReader();
while(read.Read())
{
Console.WriteLine(read[0]+......);
}
Please let me know if it helps
Laddie
}
|
|
|
|
|
Dear all,
If I create a new reference to an object, I would like to add a variable to that newly create reference. Let's say :
Foo foo = new Foo();
Now, everythime the code runs, I would like a variable added to foo , let's say :
First time it is called :
Foo foo1 = new Foo();
Second :
Foo foo2 = new Foo();
Is there an easy way of doing this ?
Cheers,
|
|
|
|
|
No.
What is the actual problem, why would you want this ?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
foo1 and foo2 are separate instances.
|
|
|
|
|
Hi ,
I too wonder of the exact situation you would require to do that.If you can tell that we should be able to help you ourt more.
However calling the new on any object will be creating a new instance itself
eg:
Foo f;
for(int i=0;i<10;i++)
{
f= new Foo();
}
will create 10 new instances rather than 1 even though you are using the same variable name.
laddie
|
|
|
|
|
Rick van Woudenberg wrote: Is there an easy way of doing this ?
Sounds like you need an array or list
List<Foo> fooList = new List<Foo>();
fooList.Add(new Foo());
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Thank you all for you swift reply.
Very true , new would create a new instance ( hence the name ). I can understand why this could be confusing. I will try to explain as good as I can why I would want this.
I create a new array of points, which I add to a ObjectList.
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)<br />
{<br />
foreach (DataGridViewRow SelectedRow in dataGridView.SelectedRows)<br />
{<br />
Points pt = new Points();<br />
pt.AddPoint(X,Y);<br />
RenderableObjects.Objects.Add(pt);<br />
}<br />
}
When I rerender the form, the points (X,Y) show on the screen. So everytime I click on a row in the datagridview, the method is called. However, everytime a new instance of Points() is added to the RenderableObjects list. But before adding the new X and Y point , I want the list to be cleared. This can be achieved by :
RenderableObjects.Objects.Remove(pt);
However you can't use this line in the same method, since a new reference is initiated and therefore the previous pt is not removed.
My though was ( and it was just a though ) : If I could add a variable to the new reference, I could specifically filter, something like :
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)<br />
{<br />
int x = 1;<br />
foreach (DataGridViewRow SelectedRow in dataGridView.SelectedRows)<br />
{<br />
points pt[x] = new Points();<br />
pt[x].AddPoint(X,Y);<br />
RenderableObjects.Objects.Add(pt[x]);<br />
int y = x -1 ;<br />
RenderableObjects.Objects.Remove(pt[y]);<br />
x++;<br />
}<br />
}
For obvious reasons , this code would not run 'cause you cannot use an array (x) size on a variable declaration. Like I said, it was just a thought. I hope I was able to clearify it a bit more.
Cheers
|
|
|
|
|
I have a solution using a DCom component,but the component was written in VC,I also insert the source project to the solution.Someone would like to tell me how should I do to debug such program step by step?
Thanks
|
|
|
|
|
You didn't mention adding the project dependencies (right click main project/Add reference/ Choose VC project). You should now be able to step into unmanaged code. However, there are lots of strange behaviours (like functions which completly ignore return statements and so on) when debugging managed and unmanaged code in the same time.
|
|
|
|
|
Oh,it's sound fine.I will have a try immediately.
I also wish I can gain some advise here in future.
Thanks very much.
|
|
|
|
|
Sorry,I had follow your guide,but (right click main project/Add reference/ Choose VC project) have no such chioce,there is only a list of all the current projects of the solution. And it forbid me to add the VC project.
I have to insert the VC project to the solution,compile and run it.but when the COM objects's functions were called,it step over but no step in.
|
|
|
|
|
Hi All,
We have a web service(developed in C#) and currently we are using "GET" method for posting the data to the server.Now we want this to change and instead of using "GET" we should be able to use the "POST" method, using the following code we are using the "GET" method.
webRequest.Method = "Get"; where webRequest is System.Net.HttpWebRequest variable.
Could you please let us know if there would be changes required in the WebService to use "POST"?
Does "GET" method has a limitation in .NET for the amount of data to be sent?
Any link/article would be greatly helpful.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Can we Query database in XSLT/XSL ?? or can we pass values to XSLT/XSL through C# or VB.Net ???
Thanks in advance.....
|
|
|
|
|
Look at XsltArgumentList. Use extension objects to provide methods to calculate or retreive external data (for example from a database) - use parameters to send data you already have into the XSLT.
|
|
|
|
|
Hi,
When should i use ?? Timer vs Thread.Sleep(int);
could u please guide me with justification?
i believe that :
I can prefer Thread.Sleep(); if my execution has to be blocked for a specific amount time, and go for Timer if i have to execute a specific job after a period.
Is it like that???? Or
Anything else and more important is there?
please guide me..
Thanks
|
|
|
|
|
Hi,
it is slightly more complex:
- you can use timers to get a single activation in future, or a periodic activation;
- the timer fires its event on some thread; for a Windows.Forms.Timer that would be
the main or GUI thread; for other timers, it is a different thread (which is good since
it does not load the GUI thread, but it also makes you need Control.InvokeRequired
and Controle.Invoke() if the timer's handler needs to touch some Control).
- you can use Thread.Sleep() to put the current thread to sleep for some time, but only
if that is acceptable to the thread. It is probably OK to do it in a worker thread
or background thread, and not in the main thread (aka "GUI thread") since during the
sleep the entire GUI comes to a halt, so it would not repaint when uncovered, you would
not be able to resize it, etc etc.
So, if you have things to do on the GUi thread thar must be kept apart in time, you
have to organize that without Trhead.Sleep(); in that case a Windows.Forms.Timer is
the right choice.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Not fair. I wanted to answer this one;P. Good answer though.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
You answered like this because it seems you have no idea about the subject.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
Yup - that's me. I'm the ultimate expert. I know nothing about everything.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete O`Hanlon wrote: I know nothing about everything
Then why is it I have seen questions you did not answer ?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I like to spread my ignorance thinly.
Deja View - the feeling that you've seen this post before.
|
|
|
|