程序不玩就忘啊!每天都要写,这个简单的插入都让我搞了半天,还没有谈结构!不过自己还是要有自信!不断总结才能进步,不断向别人学习才成长!
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class EditSearch : System.Web.UI.Page
{
public static SqlConnection create()
{
SqlConnection conn = new SqlConnection("Data Source=.Initial Catalog=ynf365db;User ID=sa;Password=123456");
return conn;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Panel1.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.Panel1.Visible = true;
}
protected void Button2_Click(object sender, EventArgs e)
{
try
{
String viewsname;
Int32 parentid;
viewsname = this.tbV.Text.ToString();
parentid = Convert.ToInt32(this.tbid.Text.ToString());
SqlConnection con = create();
con.Open();
SqlCommand cmd = new SqlCommand("insert into views (ViewsName,Parent_id) values('"+viewsname+"','"+parentid+"')", con);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script language='javascript'>alert('添加数据成功!')</script>");
}
catch (SqlException ex)
{
Console.Write("出现异常!");
}
}
}