473,513 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

code is note executing but no error

1 New Member
Expand|Select|Wrap|Line Numbers
  1. private void button2_Click(object sender, EventArgs e)
  2.         {
  3.             string data = null;
  4.  
  5.  
  6.             Excel.Application xlApp;
  7.             Excel.Workbook xlWorkBook;
  8.             Excel.Worksheet xlWorkSheet;
  9.             object misValue = System.Reflection.Missing.Value;
  10.  
  11.             xlApp = new Excel.Application();
  12.             xlWorkBook = xlApp.Workbooks.Add(misValue);
  13.             xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
  14.             con = new SqlConnection("Data Source=aswin-pc\\sqlexpress;Initial Catalog=pro;Integrated Security=True");
  15.             con.Open();
  16.             SqlCommand cmd = new SqlCommand("SELECT * FROM Details", con);
  17.             SqlDataAdapter dscmd = new SqlDataAdapter(cmd);
  18.             DataSet ds = new DataSet();
  19.             dscmd.Fill(ds);
  20.             for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
  21.             {
  22.                 for (int j = 0; j <= ds.Tables[0].Columns.Count - 1; j++)
  23.                 {
  24.                     data = ds.Tables[0].Rows[i].ItemArray[j].ToString();
  25.                     xlWorkSheet.Cells[i + 1, j + 1] = data;
  26.                 }
  27.                 xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
  28.                 xlWorkBook.Close(true, misValue, misValue);
  29.                 xlApp.Quit();
  30.                 releaseObject(xlWorkSheet);
  31.                 releaseObject(xlWorkBook);
  32.                 releaseObject(xlApp);
  33.  
  34.                 MessageBox.Show("Excel file created , you can find the file @ D:\\kk.xls");
  35.             }
  36.         }
  37.  
  38.         private void releaseObject(object obj)
  39.         {
  40.             try
  41.             {
  42.                 System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
  43.                 obj = null;
  44.             }
  45.             catch (Exception ex)
  46.             {
  47.                 obj = null;
  48.                 MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
  49.             }
  50.             finally
  51.             {
  52.                 GC.Collect();
  53.             }
  54.         }
  55.     }
  56. }
Apr 20 '14 #1
0 1276

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4310
by: Tom Dauria | last post by:
I have a form that allows the user to select some number of People from a list. The user can select one or all of the people in the list. The list has thousands of names. Once the user makes...
2
1704
by: jason | last post by:
Hello everyone, Just curious what would cause an .aspx page to not execute its inline code. <%# DataBinder.Eval... %> stuff is working just fine, but anything else contained by the <% %> tags in...
7
1201
by: Don | last post by:
Is there any way to check, in code, whether that code is being executed because of a compile as opposed to being executed because someone is just running the program? - Don
0
1156
by: pvssvikas | last post by:
Good Afternoon, I'am badly in need of help. My task :--- I would like to create a node set of elements through C++ code while executing a style sheet and process the created node set. Node...
10
5470
by: Martin Sciberras | last post by:
Hi All I am new to PHP and MySQL, so please go easy on me! The following is a simple PHP script to connect to my server. The MySQL service is running. The first echo statement displays, but the...
6
2916
by: Wernerh | last post by:
Hi I want to stop a code firing if a certain condition is not met. I only want to allow numeric entries in the textbox to allow the code to run. I tried with the first line of code to stop it, but...
4
5174
by: rmahon | last post by:
I have a situation. I was handed a Access 2007 database to work on and moved, imported data and not I am looking at the VBA code because the use told me none of the buttons are working. Well...
1
1812
by: etmanage | last post by:
This question is an outgrowth of my previous question regarding why a certain textbox wasn't updating. What happens is an addquery is called to add a record to a table and then a textbox (called...
1
1218
by: denvermuseka | last post by:
If Trim(Text4) = "" Then clsbooks.SearchBooksFrm lstBooks, "" Else clsbooks.SearchBooksFrm lstBooks, Text4.Text End If 'the code produces an error written: Run-time error 424
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.