|
添加新闻的butten代码:
public partial class admin_index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uid"] == null)
Response.Redirect("denglu.aspx");
}
protected void btn_OK_Click(object sender, EventArgs e)
{
int i = 0;
string sqlstr = "insert into news (ntitle,ncontent,pubdate) values ('" + txt_title.Text + "','" + txt_text.Text + "','" + DateTime.Now + "')";
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["sweetConnectionString"].ToString();
SqlCommand mycom = new SqlCommand(sqlstr, mycon);
try
{
mycon.Open();
i = mycom.ExecuteNonQuery();
}
catch (Exception ex)
{
throw (ex);
}
finally
{
mycon.Close();
}
if (i > 0)
{
Response.Write("<script>alert('插入成功!')</script>");
}
}
删除按钮的代码要怎么写? |
|