Click here to Skip to main content
15,561,125 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hai,


Here I am using foxpro driver for extracting tally datas.But after running that code i am getting error

"ERROR [42000] [Microsoft][ODBC Visual FoxPro Driver]Command contains unrecognized phrase/keyword." near ada.Fill(ds, "emp1");

Please give me idea to clear this and plz tell me Is this a good way to extract tally files directly into our .net application without entering into foxpro database.Plz remember that I am using only connection string for foxpro.Not the database.The sql query is suitable for this.Plz clear my doubt.

using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Odbc;
using System.IO;
using System.Text;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        OdbcConnection con = new OdbcConnection("Dsn=MICROSOFT VISUAL FOXPRO;sourcedb=d:/Tally/BSheet.dbf;sourcetype=DBF;exclusive=No;backgroundfetch=Yes;collate=Machine;null=Yes;deleted=Yes");
        con.Open();
        OdbcDataAdapter ada = new OdbcDataAdapter(" Select $Name, $Parent, $Baseunits, $ClosingBalance, $ClosingValue from StockItem", con);
        DataSet ds = new DataSet();
        ada.Fill(ds, "emp1");
        GridView1.DataSource = ds.Tables[0].DefaultView;
        GridView1.DataBind();
        DataTable dt = ds.Tables["emp1"];
        CreateCSVFile(dt, "c:\\zxxz.csv");
    }

    private void CreateCSVFile(DataTable dt, string p)
    {
        StreamWriter sw = new StreamWriter(p, false);
        int iColCount = dt.Columns.Count;
        for (int i = 0; i < iColCount; i++)
        {
            sw.Write(dt.Columns[i]);
            if (i < iColCount - 1)
            {
                sw.Write(",");
            }
        }
        sw.Write(sw.NewLine);
        foreach (DataRow dr in dt.Rows)
        {
            for (int i = 0; i < iColCount; i++)
            {
                if (!Convert.IsDBNull(dr[i]))
                {
                    sw.Write(dr[i].ToString());
                }
                if (i < iColCount - 1)
                {
                    sw.Write(",");
                }
            }
            sw.Write(sw.NewLine);
        }
        sw.Close();
    }
}


Thanks in Advance
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900