if exists (select * from dbo.sysobjects where id = object_id(n[dbo].[mybbs]) and objectproperty(id, nisusertable) = 1)
drop table [dbo].[mybbs]
go
create table [dbo].[mybbs] (
[id] [bigint] identity (1, 1) not null ,
[title] [char] (160) collate chinese_prc_ci_as null ,
[author] [char] (20) collate chinese_prc_ci_as null ,
[date_of_created] [datetime] null ,
[abstract] [char] (480) collate chinese_prc_ci_as null ,
[content] [ntext] collate chinese_prc_ci_as not null
) on [primary] textimage_on [primary]
go
textbox1,textbox2分别为提供用户输入标题和文章内容的两个textbox,
用户点击button1按钮时检查并保存文章到数据库中。
private void button1_click(object sender, system.eventargs e)
{
sqlconnection coredb=new sqlconnection();
coredb.connectionstring= "workstation id=\"gqa-eric-lv\";packet size=4096;integrated security=sspi;" +
"data source=\"gqa-eric-lv\";persist security info=false;initial catalog=coredb";
string title=textbox1.text;
string content=textbox2.text;
if(title.trim()==""||content.trim()=="")return;
string myselectquery =@"insert into mybbs (title,content) values("+ title + "," +content+")";
sqlcommand mycommand = new sqlcommand(myselectquery,coredb);
coredb.open();
sqldatareader myreader = mycommand.executereader();
myreader.close();
coredb.close();
}
文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




