我会在我的网站上创建一个评论部分,我想用下面的代码设置我的数据库。这是一个相关代码还是?我的英语不太好,但我试着把我们放在一边。asp.net c#database
该代码将在btnSend
using() {
//Insert the data to the database
}
using() {
//Select the data from the datbase and the display it
}
我会在我的网站上创建一个评论部分,我想用下面的代码设置我的数据库。这是一个相关代码还是?我的英语不太好,但我试着把我们放在一边。asp.net c#database
该代码将在btnSend
using() {
//Insert the data to the database
}
using() {
//Select the data from the datbase and the display it
}
我会写两个单独的方法中的一种用于插入件,一个用于显示。
protected void insert()
{
/// insert here
}
protected void display()
{
///display logic here
}
btnSend_click (blah blah)
{
insert();
display();
}
这样的事情是我总是这样做的。这是你问的吗?
okey谢谢你的回答我会测试并回复给你;) – 2013-02-15 21:16:47
是的,你可以在插入和显示方法中使用你的“using(){}”:)没有什么坏处。 – gaurav 2013-02-15 21:21:00
你知道按钮点击事件应该看起来像这样吗? btn_Send(对象发件人,EventArgs e) – briskovich 2013-02-15 21:21:01
看看[这个](http://stackoverflow.com/questions/9806166/how-to-create-sql-connection-with-c-sharp-code-behind-access-the-sql-server -答案。这个“教程”很清楚。 – BrOSs 2013-02-15 21:18:08
这里没有问题。虽然[''使用'可以帮助IDisposable](http://stackoverflow.com/questions/75401/uses-of-using-in-c-sharp/75483#75483),它不会“做数据库的东西”。在我的代码中,它看起来类似于使用(var ctx = _cf.Create()){var ent = _someAccess.Insert(..);使用(var ts = _cf.ForInsert())。 ctx.SubmitChanges(); ts.Complete(); }'但这可能不会帮助你。 – 2013-02-15 21:18:28