这样试下:
try
{
string sql = "insert into leave(Uid,Subject,Content) values('" + Session["who_reviewer"].ToString() + "','"+Subject.Text + "','" + this.freetextbox.Text + "')";
SqlCommand comm = new SqlCommand(sql, cn);
cn.Open();
comm.ExecuteNonQuery();
Response.Write(" <script>alert('恭喜您,留言成功!') </script>");
cn.Close();
}
catch (SqlException)
{
Response.Write(" <script>alert('很抱歉,留言失败!') </script>"); }
try
{
string sql = "insert into leave(Uid,Subject,Content) values('" + Session["who_reviewer"].ToString() + "','"+Subject.Text + "','" + this.freetextbox.Text + "')";
SqlCommand comm = new SqlCommand(sql, cn);
cn.Open();
comm.ExecuteNonQuery();
Response.Write(" <script>alert('恭喜您,留言成功!') </script>");
cn.Close();
}
catch (SqlException)
{
Response.Write(" <script>alert('很抱歉,留言失败!') </script>"); }
解决方案 »
- 关于注册控件的一个小问题
- 求一个简单的日期验证方法~!
- C# 中的Socket 状态监听
- debug没问题,但release时出现"未处理的“System.ArgumentException”类型的异常出现在 system.drawing.dll 中。",这是怎么回事?
- 关于关联文件对话框
- 批量更新数据
- 在datagrid中如何加入RadioButtonList控件,并且能够写到数据库中
- 请问下C#如何建立畸形文件夹?
- 请c#家教将5天1000
- Winform编程:如何让按确定按钮的设置窗口不符合条件时不返回主窗口?
- 未将对象引用设置到对象的实例。“/OLSCS”应用程序中的服务器错误。
- 请大哥大姐们,高手们帮帮忙!
123上面不用加“'”
public partial class reviewer_reviewer_leaveword : System.Web.UI.Page
{
SqlConnection cn;
protected void Page_Load(object sender, EventArgs e)
{
Page.DataBind();
cn = new SqlConnection("server=127.0.0.1;database=OLBSJS;uid=sa;pwd='123'"); Session["who_reviewer"] = "admin1";
}
session都没赋值啊???
cn = new SqlConnection("server=127.0.0.1;database=OLBSJS;uid=sa;pwd='123'");
pwd=123才对。
2.Server=数据库实例名