0

I'm about to ask a super basic question, but I have googled for hours on end and have yet to find a satisfactory tutorial.

Basically, I just need to access my SQL Server database via a WebPart in SharePoint. I'm using Visual Studio 2010 to code my WebPart in Visual C#, but have yet to get anywhere further than the following code:

DataSet dataSet = null;

String connectionString = "server=WIN-JAU77JEK513;User ID=WIN-JAU77JEK513/Administrator;Password=;database=db;Connection Timeout=60";
SqlConnection conn = new SqlConnection(connectionString);

String query = "SELECT * FROM dbo.table;";

conn.Open();

And that's all I got. I'm just trying to figure out basic ways of querying and updating the database, nothing fancy or anything. Can someone point me to an easy-to-understand tutorial or post me some snippets of code? I'm completely new to C# programming (having never touched it before two days ago), so I would appreciate it if there are comments or something to help me understand better.

4

1 回答 1

2

您也在使用 Sharepoint 2010 吗?您有什么理由选择 C# 路线而不是使用外部内容类型功能?这允许您设置与外部 sql 表的连接并在您的 webpart 中使用它们,就像它们是列表一样。

http://www.dotnetcurry.com/ShowArticle.aspx?ID=794

下面是 codeproject 文章的链接,该文章很好地概述了 C# 中的基本数据库编程:

http://www.codeproject.com/Articles/361579/A-Beginners-Tutorial-for-Understanding-ADO-NET

于 2013-10-21T04:47:04.867 回答