Posts

Showing posts from November, 2013

Convert List Collection to DataTable using C#

public System.Data.DataTable ConvertToDataTable<T>(IList<T> data)         {             PropertyDescriptorCollection properties =                TypeDescriptor.GetProperties(typeof(T));             System.Data.DataTable table = new System.Data.DataTable();             foreach (PropertyDescriptor prop in properties)                 table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);             foreach (T item in data)             {                 DataRow row = table.NewRow();                 foreach (PropertyDescriptor prop in properties)                ...

Excel VBA executing SQL Server multiple stored procedure

Private Sub btnGetProjectInfo_Click()                 Dim projectNo As String         Dim strConn As String         Dim conn As New ADODB.Connection         Dim cmd As New ADODB.Command         Dim ProjectInfoTable As New ADODB.Recordset         Dim OTTRdatesTable As New ADODB.Recordset         Dim TasksTable As New ADODB.Recordset                         projectNo = "123456"         strConn = "provider =sqloledb; Data Source = ******; Initial Catalog = *********; User Id = ********; Password = ************;"      ...

Get Data from SQL DB to Excel using VBA script (Macros)

create one button in Excel sheet "Get Data". open sheet in Design view mode. right click on button and select "View Code" option in excel. it will open "Visual Basics" coding window. My button event is " Private Sub btnGetData_Click() ". please follow the code. for getting the data from SQL db to Excel. before execution of this code we need to add ADODB class reference in this Visual Basics. ADD Reference: in Visual Source window click on Tools--> References --> select "Microsoft ActiveX Data Objects 2.6 Library" in this case i am using Microsoft office 2007 version. Private Sub btnGetData_Click()                 If Range("C1") = "" Then                                 MsgBox ("Project number required.")      ...

Update SharePoint Group with group owner using Power Shell script.

I am updating SharePoint site collection group owner with user in first case, in second case updating group owner with group. Case 1:  Group owner updating with user. #Get the SPWeb $web = Get-SPWeb “http://SP2010:8080/sites/TestSite” #Get the Group $group = $web.SiteGroups["Project Managers"] #Get the User $user = $web.EnsureUser("globaldomain\e939383;") #Assign that user as the owner $group.Owner = $user #Update the Group $group.Update() Case 2:  Group owner updating with GroupName. #Get the SPWeb $web = Get-SPWeb “http://SP2010:8080/sites/TestSite” #Get the Group $group = $web.SiteGroups["Project Managers"] #Get the group name $group =$web.SiteGroups["Project Managers"] #Assign that user as the owner $group.Owner = $ group #Update the Group $group.Update() in this second case "Project Managers" has the full control on that group. But in first case " globa...