Home > SharePoint Server > การ import data จาก sql ไปที่ sharepoint

การ import data จาก sql ไปที่ sharepoint

ในตอนนี้ได้แสดงถึงการ import data จาก sql เข้าไปที่ sharepoint อย่างง่ายที่สุด โดยใช้ api ของ sharepoint ครับ

System Requirement:

1. Visual studio2008

2. SQL Server 2008 (Adventureworks2008 sample database)


Add Reference:

1. Microsoft.Sharepoint.dll

Code Listing:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using Microsoft.SharePoint;
namespace demoImportSharepoint
    class Program
        static void Main(string[] args)

            //ติดต่อ sql
            SqlConnection con= new SqlConnection(@”Data Source=sharepoint;Initial Catalog=Adventureworks2008;Integrated Security=True”);
            SqlCommand com= new SqlCommand(“Select Title, Phone from person.person”, con);

            //ติดต่อ sharepoint

            SPWeb web = new SPSite(http://sharepoint).OpenWeb();
            SPList list= web.Lists[“Person”];
            SPListItem item;

            SqlDataReader reader = com.ExecuteReader();
            while (reader.Read())
                item = list.Items.Add();
                item[“Title”] = reader[“Title”];
                item[“Phone”] = reader[“Phone”];

หลักสูตรอบรม SharePoint (Click)

Categories: SharePoint Server
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: