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

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#

上一篇:Redis在C#中的使用


下一篇:C#客户端嵌入Chrome浏览器的实现