none
LInq with data table to generate a CSV in Window programming RRS feed

  • Question

  • Hi Everone,

            Am new to the concept Linq.I created a var where i joined 3 tables to get the data and then bind it in a datatable and create a csv file.

    Now i want to use an additioanl table in the same variable to be bind with the datatable but my problem is i cant use join here since i dnt have any common col or primary col in this additional table.How do i add this extra table?

    Please help me.Below is my code:

    public

     

    void GetDetails()

     

    string filepth="C:\niki";

     

     

    DataClasses1DataContext da = new DataClasses1DataContext();

     

     

    //ApplicationDataDataContext da = new ApplicationDataDataContext();

     

    var query = from q in da.Controls

     

     

    join o in

    da.Errors

    on

    q.object_id

    equals o.ER_GUID join f in da.ErrorTypes on

     

    equals f.ET_Error_Id

     

    select new

    {

    q.CT_GUID_Type,

    o.ER_Error_ID,

    o.ER_Error_Date,

    f.ET_Error_Description

    };

     

    var bth = from b in da.Batches

     

     

    where b.BT_Batch_End != null

     

    select b;

     

    DataTable dt = new DataTable();

     

     

    DataTable dt1 = new DataTable();

     

     

    IEnumerable<DataRow> querys = query.AsEnumerable()

     

     

    as IEnumerable<DataRow>;

     

     

    IEnumerable<DataRow> b1 = bth.AsEnumerable()

     

     

    as IEnumerable<DataRow>;

    dt1 = b1.CopyToDataTable<

     

    DataRow>();

    dt = querys.CopyToDataTable<

     

    DataRow>();

     

    public void CreateCSVfile(DataTable dt, string filepth)

     

    StreamWriter sw = new StreamWriter(filepth, false);

     

     

    int icolcount = dt.Columns.Count;

     

     

    for (int i = 0; i < icolcount; i++)

     

    if (i < icolcount - 1)

    { sw.Write(

     

    ",");

     

    foreach

     

    DataRow drow in dt.Rows)

     

    for (int i = 0; i < icolcount; i++)

     

    if (!Convert.IsDBNull(drow[i]))

     

    if (i < icolcount - 1)

     

    ",");

     

     


    }

    }

    sw.Write(sw.NewLine);

    }

    sw.Close();

    }

    {

    sw.Write(

    {

    sw.Write(drow[i].ToString());

    }

     

    {

     

    {

     

    (

    }

    }

    sw.Write(sw.NewLine);

     

    {

    sw.Write(dt.Columns[i]);

     

    {

     

    CreateCSVfile(dt1, filepth);

    CreateCSVfile(dt, filepth);

    }

     

     

     

    o.ER_Error_ID

    {

     


    Sumit shrivastava
    • Moved by Aspen VJ Monday, January 24, 2011 6:04 AM (From:Windows Forms General)
    Friday, January 21, 2011 1:05 PM

All replies

  • Hi Sumit,

    ·         Base on your description,  I think it is little about winform.

    This forum is dedicated to Windows Forms technology. I'm moving this thread from Base "Windows Forms" to "LINQ To SQL" forum, since this issue is related to Linq. There are more Linq experts in that forum.

    Thank you for understanding and supporting.

     

    Best Regards,

    Vin Jin


    Vin Jin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 24, 2011 6:04 AM