|
Hi all
We need to do a small application that, amongst other things, need to extract some data from a MS Access database into a MS Excel worksheet. Connecting from my C# windows application I can connect to the MS Access database and extract the necessary data using the Jet driver (Microsoft.Jet.OLEDB). I am reading the data into a OleDbDataReader.
I am not sure how to do the MS Excel part. I would like to use the Jet driver (Microsoft.Jet.OLEDB). for this too, because then I do not have to reference the Microsoft Excel COM library in my project (as far as I know).
The following type of code works to open the connection to my Excel worksheet, but how would I add the records from my OleDbDataReader into the worksheet. Possible code probably needs to be where the ”XXXXXXXXXXXXXXXX” is in the code.
private void UpdateExcel()
{
OleDbConnection cnExcel = null;
try
{
Cursor.Current = Cursors.WaitCursor;
StringBuilder sbConn = new StringBuilder();
sbConn.Append(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Stocks.XLS");
sbConn.Append(";Extended Properties=");
sbConn.Append(Convert.ToChar(34));
sbConn.Append("Excel 8.0;HDR=No;IMEX=2");
sbConn.Append(Convert.ToChar(34));
cnExcel = new OleDbConnection(sbConn.ToString());
cnExcel.Open();
OleDbCommand cmdExcel = new OleDbCommand("XXXXXXXXXXXXXXXX",cnExcel);
cmdExcel.ExecuteNonQuery();
cnExcel.Close();
Cursor.Current = Cursors.Arrow;
}
catch(Exception ex)
{
cnExcel.Close();
MessageBox.Show(ex.Message);
}
}
Alternatively is there a better, more streamlined way?? Perhaps something like the Data Transformation Services in SQL Server where I can export from Access into Excel? If there is, how could I do that from within C#?
|
|
|
|
|
Just use an 'Insert into' statement for your "XXXXX" The table name should be the worksheet name with '$" appended (SHEET1$), and the column names A, B,C etc.
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
The opposite of the religious fanatic is not the fanatical atheist but the gentle cynic who cares not whether there is a god or not.
Eric Hoffer
|
|
|
|
|
Hi! Can someone please help me with the code I posted below "Save Button". I really need an expert's adice on that. Thanx! Greatly appreciated!
|
|
|
|
|
I have a question that has been touched upon in previous articles regarding calling dlls from C#.
I have a DLL that has been built in Embedded Visual C++ 4.0. I have a 'Solution' in the .Net IDE that contains a C# project. I need to be able to load and call the functions in the DLL constructed in EVC4 (real C++ - not through CLR. i.e. not managed C++ in .Net).
It would seem that the way I go about doing this is to make a proxy dll that is called from the C# project to a managed C++ project. From the managed C++ project, calls are made for the LoadLibrary, and GetProcAdress to the functions in the EVC4 dll. Am I going down the right track?
Can anybody please give me some steps about solving this problem?
|
|
|
|
|
You can use P/Invoke (see www.pinvoke.net[^]) to call native (eg. C++ or Win32) DLLs from any managed language (C# in this case.)
I don't know about a DLL created with EVC though.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Like Luis said, pinvoke is a better option if you are going to use only a few functions from the DLL and you know the DLLs you are going to use, at compile time. It's very easy to do, just declare a static extern method with the equivalent C# signature of the DLL functions, mark it with the DllImport attribute, and you are done.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi
I have some records say 1000 Nos fetched from SQL and stored in a Dataset.
Now I need to fetch and store top 1-50 records in another dataset and top 51-100 records in another dtaset and so on.
Could any one help me how to transfer records from one Dataset to another dataset?
Regards
San
|
|
|
|
|
Surely what you want is a stored procedure that pages your data ? The way to do this is to do two selects, that are nested, use the TOP statement in both, and have one ordered ASC and the other DESC. So the first grabs from the first record through to the last one you want, the other inverts the order and selects from the last one you want to the first one you want.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Sorry My idea is to manipulate the data locally, .
My ultimate aim is to do paging in dataGrid since winform GataGrid is not supporting the Paging.
|
|
|
|
|
Really ? Only the web DataGrid does paging ? I didn't realise that.
Well, the easiest thing would still be a stored proc that takes a page number and size, but if you want to limit your database access, then I guess you'd store the full table locally, and build a datasource from it that you bind to the grid, selecting only the current page rows.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I would add a DataColumn with AutoIncrement set to true to the table, and then use a DataView and its RowFilter property to just return the records with that column from 1 to 50.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
hi all,
My Question is like this:
Our network is workgroup.Then How do we Logg on to NETWORK Computer using C#?.
I need to handle a service in other computer ..but it says that "You haven't enough previleges to access this Service Control"
So I need to hardcode user name and password of that machine.So what is the method or way to logg on to NETWORK computer..?
But our NETWORK is a WORKGROUP not a Domain.
I know there is way to logg on to other computer if our computers are in a DOMAIN..
So please any one tell me how to access workgroup computer using C#?
thanks in advance.
|
|
|
|
|
I run a workgroup at home, and in my experience, you need to either add a $ to the drive name you use in your path ( which gets you in as admin ), i.e. \\myPC\c$\My Documents\etc., or you need to set up the permissions you require on the machine you're connecting to.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thank you very much!
program jys 2003 77 60 kill Japan.
|
|
|
|
|
Do you mean the IP of the host computer (the one the app is running on?) In a Windows Forms app use this code:
string strHostName = "";
string strIP;
try
{
strHostName = Dns.GetHostName();
IPAddress [] ips = Dns.Resolve(strHostName).AddressList;
if(ips.Length >= 1)
strIP = ips[0].ToString();
else
strIP = "(error)";
}
catch
{
if(strHostName == null || strHostName.Length == 0)
strHostName = "(error)";
strIP = "(error)";
} If you are developing an ASP.NET application and you want to get the IP of the computer connecting to you, I suppose it's possible, but I have no idea.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I means to How do I find the IP address of the Client App connecting to a dot NET remoting service(C#).
program jys 2003 77 60 kill Japan.
|
|
|
|
|
Well, then I have no idea.
This is why you should explain your question the best you can the first time. "How to get client IP" is just to vague. There are many situations where that phrase makes sense and there's no way for us to know which in particular is your situation. By asking better questions, you can be sure of getting better answers that really address your problem, and not, like in this case, an answer that took some time to write that is totally unrelated.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
i want some information about all port
|
|
|
|
|
I live in Hobart. Hobart is a port, but not a busy one. Melbourne is a busier port, but Sydney is busier again.
If you wanted other information, be a little more specific about what you're trying to do.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Maybe he meant something like this.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
The really sad part is this is the second time he's posted this very same statement! He deleted the first one after getting a similar response.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I have a big array n*n matrix in an .xls (Excel Spreadsheet) and I want to read it into the my C# which calculates the inverse of it. I am not sure how to read the xls file into a 2D array.
n is variable, i.e. it is not known beforehand. It can be 300, 400 0r 500 or any value. Basically, the user gives the input as the file name in which he has storted the matrix.
And does anyone aware of any fast and qucik algorithm by which I can check if a large matrix is singular or not.
Regards
|
|
|
|
|
Hey folks,
I am not very good at C# programming.
I want to write a piece of C# code to change the Pool size in Application pooling of a COM+ component?
Do you guys know how can I do that.
Thanks a bunch.
Tommy.
|
|
|
|
|
Hi! Im creating a form in which i retrieve data from a database and attach it to a grid. I need to have a function in which if i click the save button the results of the retrieved data will be saved as a "text" file. cane someone please tell me what's wrong with my code bcoz whenever i click my save button it doesn't save at all. here's my code:
private void btnSave_Click(object sender, System.EventArgs e)
{
OdbcConnection cnn = new OdbcConnection();
cnn.Open();
OdbcCommand cmmd = new OdbcCommand();
OdbcDataAdapter adp = new OdbcDataAdapter (cmmd);
DataSet ds_emp = new DataSet();
adp.Fill(ds_emp);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for(int i=0;i<=ds_emp.Rows.Count - 1; i++)
{
for(int q=0;q<=ds_emp.Columns.Count - 1; q++)
{
sb.Append(ds_emp.Rows[i][q].ToString());
}
sb.Append(" ");
}
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=*.txt");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.text";
System.IO.StringWriter strWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(strWrite);
Response.Write(sb.ToString());
}
where ds_emp is the retrived data. Is there something wrong with my code? It builds but it doesn't work. Thanx for all your replies! I appreciate it
thanx
|
|
|
|
|
I have the following URL:
http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&u=/netahtml/search-adv.htm&r=2&p=1&f=G&l=50&d=ptxt&S1=((teeth+OR+member)+OR+provide)&OS=+(teeth+OR+member)+OR+provide&RS=((teeth+OR+member)+OR+provide)
Accessing it with the following code snippet (which works for other sites):
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
throws a WebException (timeout). Accessing the same URL with IE works fine. I compared the request header sent by the code and the one sent by IE and they are identical. The user agent has been set to "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50215)"
I even increased the request timeout to a massively huge value and it didn't make any difference.
|
|
|
|