一个简单问题,请教一下!
string strconn = ConfigurationSettings.AppSettings["connstring"];
SqlConnection conn = new SqlConnection(strconn);
SqlCommand cm = new SqlCommand("aaa_", conn);
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add("@ph", SqlDbType.VarChar, 50, "ph").Value = textbox1.Text;
conn.Open();
cm.ExecuteNonQuery();
1、以上代码是可以提交插入数据,但我现在要返回一句"提交成功",请问应该怎么弄?
2、提交成功后,清空textbox1的数据,防止重得提交 --------------------编程问答--------------------
有个问题--------------------编程问答-------------------- TextBox1.text=""
你打开了连接
conn.open()
但是你没有关闭
conn.close()
respose.write("Success");
response.write("提交成功!") --------------------编程问答--------------------
--------------------编程问答-------------------- string strAlert = "提交成功";
string strconn = ConfigurationSettings.AppSettings["connstring"];
SqlConnection conn = new SqlConnection(strconn);
SqlCommand cm = new SqlCommand("aaa_", conn);
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add("@ph", SqlDbType.VarChar, 50, "ph").Value = textbox1.Text;
conn.Open();
int i = cm.ExecuteNonQuery();
if(i>0)
{
//成功了
}else
{
//失败了
}
HttpContext context = HttpContext.Current;
context.Response.Write("<script language=javascript>window.alert('"+strAlert + "')</script>");
如果你是在page里面执行的话,就这样就可以,如果是在类库里面执行,那么需要将System.Web添加引用进去 --------------------编程问答-------------------- if(m.ExecuteNonQuery()==1)
{
response.write("提交成功!<script>window.location=window.location.href;</script>")
} --------------------编程问答-------------------- 1,你可以在存储过程中返回受影响的行数,假入大于1就添加成功,就可以response.write("<script lanuage='javascript'>alert('提交成功!')</script>")
2,可以在提交成功后重新加载这个页面,也就是从新跳转到这个页面,就OK了 --------------------编程问答-------------------- 我参照了上面这样写也不行啊,虽然插入成功,但不弹出----提交成功
--------------------编程问答--------------------
try
{
int i = cm.ExecuteNonQuery();
if (i > 0)
{
Response.Write("提交成功");
}
else
{
Response.Write("<script language='javascript'>arert('投诉提交失败')</script>");
}
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
finally
{
conn.Close();
}
--------------------编程问答-------------------- 我需要的是弹出框,然后清完textbox的数据 --------------------编程问答--------------------
string strconn = ConfigurationSettings.AppSettings["connstring"];
SqlConnection conn = new SqlConnection(strconn);
SqlCommand cm = new SqlCommand("aaa_", conn);
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add("@ph", SqlDbType.VarChar, 50, "ph").Value = textbox1.Text;
conn.Open();
int i = cm.ExecuteNonQuery();
if (i > 0)
{
Response.Write("提交成功");
}
else
{
Response.Write("<script language='javascript'>arert('投诉提交失败')</script>");
}
response.write(" <script lanuage='javascript'>alert('提交成功!') </script>")
这是提交成功?
response.redirect("aa.aspx");
可是这样没有提示成功啊 --------------------编程问答--------------------
--------------------编程问答--------------------
string strconn = ConfigurationSettings.AppSettings["connstring"];
SqlConnection conn = new SqlConnection(strconn);
SqlCommand cm = new SqlCommand("aaa_", conn);
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add("@ph", SqlDbType.VarChar, 50, "ph").Value = textbox1.Text;
conn.Open();
int i = cm.ExecuteNonQuery();
if (i > 0)
{
this.ClientScript.RegisterStartupScript(typeof(string), "oksdsf", "<script>alert('提交成功!')</script>");
this.textbox1.Text = "";
}
else
{
this.ClientScript.RegisterStartupScript(typeof(string), "oksdsf", "<script>alert('提交失败!')</script>");
}
string strconn = ConfigurationSettings.AppSettings["connstring"];
SqlConnection conn = new SqlConnection(strconn);
SqlCommand cm = new SqlCommand("aaa_", conn);
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add("@ph", SqlDbType.VarChar, 50, "ph").Value = textbox1.Text;
conn.Open();
int i = cm.ExecuteNonQuery();
if(i>0)
{
this.textbox1.Text = "";
this.ClientScript.RegisterStartupScript(typeof(string), "ok", "<script>alert('提交成功!')</script>");
//成功了
}else
{
this.ClientScript.RegisterStartupScript(typeof(string), "ok", "<script>alert('提交失败!')</script>");
//失败了 }
补充:.NET技术 , ASP.NET