您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

ASP.NET往数据库添加数据实例

2025/8/8 23:08:12发布17次查看
使用sql server建立一个数据库hovertree
然后使用以下脚本创建表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
那么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控件
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product