Table Types

  • Dear All,

    I am having a data table in .Net with a single column which is filtered from a data got from the SQL.

    Now passing the values in the column, I have to get the detailed data for the filtered values.

    I don't know how to pass the Data Table to SQL.

    I can do it my making the values as comma separated valued string.

    But for this I have to loop the data in the application.

    Can any one help me to perform it easily without causing the performance issue?

    Thanks a lot in advance.

    Best Regards,

    M. J. Jaya Chitra

    [font="Arial"]Nothing is impossible with Hard Work[/font]:)

  • In SQL Server 2008, it is possible to pass table as parameter.

    In SQL Server 2005, you can use the work around mentioned in link:

    http://www.sommarskog.se/arrays-in-sql-2005.html

  • AGREED. you can use table parameters in SQL Server 2008 (mines still 2005 T__T) but theres another way without using loop... try storing them in xml and then extracting them within the sprocs

    _____________________________________________
    [font="Comic Sans MS"]Quatrei Quorizawa[/font]
    :):D:P;):w00t::cool::hehe:
    MABUHAY PHILIPPINES!

    "Press any key...
    Where the heck is the any key?
    hmmm... Let's see... there's ESC, CTRL, Page Up...
    but no any key"
    - Homer Simpson
  • Jaya: can you post your code?

    Thanks

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Dear Friends,

    Thank you all for your efforts.

    Already I have the function in order to split the string to tabular values from this site.

    Now in the front end I just extracted the single column values and converted the rows to array and then to string array and joined it as comma separated values and now I have achieved the functionality without the loop in the front end as well in the DB.

    The sample code in C#.Net is:

    private void btnConvertToCSV_Click(object sender, EventArgs e)

    {

    DataTable datatable= myDataSet.Tables[0].DefaultView.ToTable(true, "Column1");

    DataRow[] dr = new DataRow[datatable.Rows.Count];

    datatable.Rows.CopyTo(dr, 0);

    string[] rowValues= Array.ConvertAll(dr, new Converter (DataRowToString));

    string combinedValue = String.Join(",", rowValues);

    MessageBox.Show(combinedValue);

    }

    public static string DataRowToString(DataRow dr)

    {

    return Convert.ToString(dr[0].ToString());

    }

    [font="Arial"]Nothing is impossible with Hard Work[/font]:)

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply