Wednesday, 2 December 2015

Comma separated values using linq from dataset in C#


 DataSet ds = new DataSet();
            System.Data.DataTable dtResults = new System.Data.DataTable();
            System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("server=testserver;uid=testuser;pwd=pwd;database=testDB");
            con.Open();
            System.Data.SqlClient.SqlCommand cmd = new SqlCommand("SPName", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter DA = new SqlDataAdapter(cmd);
            DA.Fill(ds);

            if (ds.Tables != null && ds.Tables[0].Rows.Count > 0)

            {
                string ourstring = String.Join(",", ds.Tables[0].AsEnumerable().Select(x => x.Field<int>      ("ColumnName").ToString()).ToArray());

            }

No comments:

Post a Comment

Row based styling for Primeng DataTable using Angualr 2,4

------------------------------------Component.Html---------------- < p -dataTable id = "Tbl" [ rowStyleClass ]= " Fu...