Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
TXT-CSV file 2 grid
Message
De
07/03/2007 10:12:57
John Baird
Coatesville, Pennsylvanie, États-Unis
 
 
À
07/03/2007 10:04:25
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01201486
Message ID:
01201491
Vues:
22
Here is a snippet of working code:
            DataTable dt = null;

            //Excel 2003
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                "Data Source=" + fileName + ";" +
                "Extended Properties=Excel 8.0;";
            OleDbConnection objConn = new OleDbConnection(connectionString);
            try
            {
                objConn.Open();
            }
            catch
            {
       		return null;
            }
  
            OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [" + parm.excelSheetName + "$]", objConn);
            OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
            objAdapter1.SelectCommand = objCmdSelect;

            try
            {
                dt = new DataTable("ExcelTable");
                objAdapter1.Fill(dt);
                objConn.Close();
	    }
            catch (Exception e)
            {
                throw e;
            }
            return dt;
>Hi all,
>
>How to get this code working:
>
>
>using System.Data.OleDb;
>using System.Data.SqlClient;
>
>public partial class _Default : System.Web.UI.Page
>{
>    protected void Page_Load(object sender, EventArgs e)
>    {
>        string strConn, strSQL;
>        // strConn = "provider=SQLOLEDB; Data Source=E:\\_ASP\\TXTUzorak.txt; Extended Properties='text;HDR=No;FMT=Delimited'";
>        strConn = "provider=SQLOLEDB; Data Source=E:\\_ASP\\TXTUzorak.txt;Integrated Security=True";
>
>
>                  strSQL = "SELECT * from TXTUzorak.txt" ;
>
>        OleDbConnection cn = new OleDbConnection();
>        cn.ConnectionString = strConn;
>        cn.Open();
>
>
>        //OleDbDataAdapter da = new OleDbDataAdapter(strSQL, cn);
>        //DataSet ds = new DataSet();
>        //da.Fill(ds, "Kupci");
>
>        OleDbCommand    izvrsi = new OleDbCommand(strSQL, cn);
>        OleDbDataReader citac  = izvrsi.ExecuteReader();
>
>        cn.Close();
>
>        GridView1.DataSource = citac;
>        //GridView1.DataSource    = ds;
>        //GridView1.DataMember    = "Kupci";
>        GridView1.DataBind() ;
>
>    }
>
>
>
>No error message available, result code: DB_E_ERRORSOCCURRED(0x80040E21).
>
>
>Also, not clear this :
>
>a) If I use //strConn, got "syntax error.."
>b) are provider= and providerName= equal ?
>c) if I use System.Data.SqlClient , got "not rgistered on this machine..."
>d) I tried also alternate variant (with // in front) but no luck ...
>
>TIA,
>gojko
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform