床头挂电器:string cn = System.Configuration.ConfigurationManager.AppSettings["Connstring"];

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 23:35:45
string cn = System.Configuration.ConfigurationManager.AppSettings["Connstring"];
SqlConnection oSQLConn = new SqlConnection();
oSQLConn.ConnectionString = cn;
oSQLConn.Open();
str = "select Area from CusTomer_newresourceall where mobilno='" + mobile.Text.Trim().Substring(1, 6) + "'";
SqlCommand comm = new SqlCommand(str, oSQLConn);
string area = Convert.ToString(comm.ExecuteScalar());

if (area == "")
{
area = "其它";
}
string strr = "insert into CusTomer_guest (mobilno,content,guestname,area,marktime,kfxm) values ('" + mobile.Text.Trim() + "',' 没填','无','" + area + "',getdate(),'" + Session["kfxm"] + "')";
SqlCommand inst = new SqlCommand(strr, oSQLConn);
try
{
inst.ExecuteNonQuery();
string message = "数据添加成功!!";
this.Response.Write("<body onload=" + "javascript:alert('" + message + "');" + ">");
Panel2.Visible = false;
Panel1.Visible = true;
db();
}
catch
{
string message = "数据添加失败!!";
this.Response.Write("<body onload=" + "javascript:alert('" + message + "');" + ">");
}
finally
{
oSQLConn.Close();
}
}
else { Response.Redirect("display.aspx"); }

帮我精简一下代码,指点一下