首页 > Windows开发 > 详细

数据增删改通用 asp.net c#

时间:2020-02-09 00:17:03      阅读:69      评论:0      收藏:0      [点我收藏+]

protected void Button1_Click(object sender, EventArgs e)
{
int res;
string c1 = this.TextBox1.Text.ToString();
string dw = this.DropDownList1.SelectedValue;
string commstr = @"update data set c1=‘" + c1 + "‘" + @"where dw=‘" + dw + "‘";
//"insert into data(c1) values(‘" + c1 + "‘)"


OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=|datadirectory|data.mdb;");
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
OleDbCommand cmd = new OleDbCommand(commstr, conn);

try
{
res = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new Exception("error", ex);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}

if (res > 0)
{
Response.Write("ok");
}
else
{
Response.Write("fail");
}

}

数据增删改通用 asp.net c#

原文:https://www.cnblogs.com/houweidong/p/12285538.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!