I have console application that queries a sharepoint list. I need to then do a sql insert of those query results into a separate sql table. The sharepoint part is taken care of, now I just need to do the sql insert, but I can't get a grasp on how to make that happen. I assume I need to construct the insert in the foreach loop, but that's about as far as I can get. I need to know how to establish the db connection, construct the query and execute it.
Here's what I have for getting the sharepoint list data:
Any help would be greatly appreciated!
Here's what I have for getting the sharepoint list data:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Data.Odbc;
namespace GPSNotifications
{
class Program
{
static void Main(string[] args)
{
using (SPSite curSite = new SPSite("[URL unfurl="true"]http://zanett-spdev-rb"))[/URL] //[URL unfurl="true"]http://gps.technicolor.com[/URL]
{
using (SPWeb curWeb = curSite.OpenWeb())
{
//create our query
SPQuery curQry = new SPQuery();
//configure the query
curQry.Query= @"
<Query>
<Where>
<Gt>
<FieldRef Name='Created'/>
<Value Type='DateTime'>DateTime.Now.AddMinutes(-15);</Value>
</Gt>
</Where>
</Query>
";
//get our list
SPList curList = curWeb.Lists["Notifications"];
//get the collection of items in the list
SPListItemCollection curItems = curList.GetItems(curQry);
//enumerate the items in the list
foreach (SPListItem curItem in curItems);
{
// do sql insert
}
Console.WriteLine();
}
curSite.RootWeb.Dispose();
}
}
}
}
Any help would be greatly appreciated!