第六天
學習目的
掌握如何用ADO
我們學得好快
為了不使注意力分散
仍用昨天的方法新建一數據表
[NewsArticleID] [int] IDENTITY (
[Title] [nvarchar] (
[SubTitle] [nvarchar] (
[Content] [ntext] COLLATE Chinese_PRC_CI_AS NOT NULL
[Writer] [nvarchar] (
[PubTime] [datetime] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
ALTER TABLE [dbo]
CONSTRAINT [DF_NewsArticle_PubTime] DEFAULT (getdate()) FOR [PubTime]
CONSTRAINT [PK_NewsArticle] PRIMARY KEY CLUSTERED
(
[NewsArticleID]
) ON [PRIMARY]
GO
按昨天的方法加入頭部的語句
private void btnPublish_ServerClick(object sender
{
string strConnection = ConfigurationSettings
// 連接SqlServer數據庫
SqlConnection conn = new SqlConnection(strConnection);
// 建立SqlCommand
SqlCommand cmd = conn
cmd
+
+
+
+
conn
//Response
// 插入記錄
try
{
cmd
}
catch (Exception ex)
{
Response
}
finally
{
conn
}
}
注意Command對象的ExecuteNonQuery()方法使用
From:http://tw.wingwit.com/Article/program/net/201311/15733.html