日期:2014-05-17 浏览次数:20526 次
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
string t1 = this.TextBox1.Text;
SqlCommand cmd = null;
SqlConnection con = null;
try
{
con = new SqlConnection("server=192.168.2.169;uid=sa;pwd=sa;database=NewTrafficManagement");
string str = string.Format("insert into Areas(AreaName)values('{0}')", t1);
cmd = new SqlCommand(str, con);
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write("<script>alert('ex.Message')</script>");
}
finally
{
if (cmd != null)
{
cmd.Dispose();
}
if (con != null)
{
con.Dispose();
}
}
}
}