Home >Backend Development >C#.Net Tutorial >ASP.NET adds data instance to database

ASP.NET adds data instance to database

巴扎黑
巴扎黑Original
2016-12-19 16:00:472375browse

Use Sql Server to create a database hovertree

Then use the following script to create the table hovertree_usermessage

USE [hovertree]
GO
/****** Object: Table [dbo].[hovertree_usermessage] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE 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]
GO
ALTER TABLE [dbo].[hovertree_usermessage] ADD CONSTRAINT [DF_hovertree_usermessage_hvtTime] DEFAULT (getdate()) FOR [hvtTime]
GO

Then the C# code for using the KeleyiSQLHelper class to add data to the database is:

C# code

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);

where txtTitle, txtContent, and txtUser are ASP.NET TextBox control

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn