使用Sql Server建立一個資料庫hovertree
然後使用以下指令碼建立表hovertree_usermessage
USE [hovertree]GO/****** Object: Table [dbo].[hovertree_usermessage] ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[hovertree_usermessage]([hvtId] [int] IDENTITY(1,1) NOT NULL,[hvtTitle] [nvarchar](500) NULL,[hvtContent] [nvarchar](max) NULL,[hvtUser] [nvarchar](50) NULL,[hvtTime] [datetime] NULL,[hvtReply] [nvarchar](max) NULL,[hvtIsShow] [bit] NULL,CONSTRAINT [PK_hovertree_usermessage] PRIMARY KEY CLUSTERED ([hvtId] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOALTER TABLE [dbo].[hovertree_usermessage] ADD CONSTRAINT [DF_hovertree_usermessage_hvtTime] DEFAULT (getdate()) FOR [hvtTime]GO
那麼C#使用KeleyiSQLHelper類往資料庫添加資料的代碼為:
C#代碼
string m_sql="insert into hovertree_usermessage (hvtTitle,hvtContent,hvtUser)values(" +SQLTools.GetQuotes(txtTitle.Text)+"," + SQLTools.GetQuotes(txtContent.Text)+"," +SQLTools.GetQuotes(txtUser.Text) +")"; KeleyiSQLHelper.ExecuteSql(m_sql);
其中txtTitle、txtContent、txtUser為ASP.NET的TextBox控制項