title: Conversion of sql table to excel table
body: <p>In my application I want database data exported to Excel sheet and I have to make this file as readonly and  I want to display message if the user try to edit the Excel Like-you are not allowed to edit this sheet I'm doing this in console application. </p>
  
  <p>I have written code like this:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Data.SqlClient;
  using System.Data.Odbc;
  
  namespace ConsoleApplication1{
  
  class Program
  {
  
      static void Main(string[] args)
      {
  
          SqlConnection con = new SqlConnection
           ("");
          con.Open();
          SqlCommand cmd = new SqlCommand
          ("select Temprature,time,date from temprature3 ", con);
          SqlDataReader data = cmd.ExecuteReader();
          OdbcConnection dcon = new OdbcConnection();
          dcon.ConnectionString = @"Driver={Microsoft Excel Driver(*.xls)};Create_DB=C:\Documents andSettings\Administrator\Desktop\Excel\Report.xls;DBQ=C:\Documents and Settings\Administrator\Desktop\Excel\Report.xls;
    ReadOnly=True";
          dcon.Open();
          OdbcCommand dcom=new OdbcCommand
             ("create table Report new
             (Temperature double,Time datetime,Date datetime)",dcon);
          dcom.ExecuteNonQuery();
          Console.WriteLine("table has been created");
          OdbcCommand dinsert=new OdbcCommand("insert into Report values(?,?,?)",dcon);
          OdbcParameter Temprature=new OdbcParameter("@Temperature",OdbcType.Double);
          OdbcParameter Time=new OdbcParameter("@Temperature",OdbcType.DateTime);
          OdbcParameter Date=new OdbcParameter("@Temperature",OdbcType.DateTime);
          dinsert.Parameters.Add(Temprature);
          dinsert.Parameters.Add(Time);
          dinsert.Parameters.Add(Date);
          int count=0;
          while(data.Read())
          {
              Temprature.Value=data[0];
              Time.Value=data[1];
              Date.Value=data[2];
              dinsert.ExecuteNonQuery();
              count=count+1;
  
          }
  
          Console.WriteLine("------------------------------------------------------");
          Console.WriteLine(count+"Number of rows are exported to excel");
          Console.WriteLine("-------------------------------------------------------");
          Console.ReadLine();
      }
  }
  }
  </code></pre>
  
  <p>I'm getting error like this:</p>
  
  <blockquote>
    <p>ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified</p>
  </blockquote>