有个button
在事件 中 代码 添加到数据库
string sguestTitle = newsTitle.Text;
        string sguestkind = DropDownList1.SelectedValue;
        string sguestContent = newsContent.Text;
            TwwSqlHelper tww = new TwwSqlHelper();//一个数据库类 
            tww.ExecuteDataSet("Insert Into News(Title,Content,Datetime,Kind)Values('" + sguestTitle + "','" + sguestContent + "' ,'" + System.DateTime.Now.ToString() + "', '" + sguestkind + "')", CommandType.Text, false);
---------------------------------------------------------------------------------------------------------------------------------------
请问如何确定 它执行添加命令成功了呢?  弄个label提示下也行的啊。
假如添加成功了 用个脚本 弹出一个对话框  ①想要继续添加么?②取消 如何实现 
请教高手 呵呵  先谢谢各位了啊。

解决方案 »

  1.   

    TwwSqlHelper 
    這個類是你自己寫的?你這個方法ExecuteDataSet加個返回值啊,用來判斷成功還是失敗~
      

  2.   

    private string ExecuteScalar(string commandTextOrProcedureName, CommandType commandType, bool isNewConnection)
            {
                string result = "";
                if (isNewConnection)
                {
                    using (SqlConnection newConn = new SqlConnection(TwwSqlHelper.ConnString))
                    {
                        try
                        {
                            Comm = new SqlCommand(commandTextOrProcedureName, newConn);
                            newConn.Open();
                            if (Comm.ExecuteScalar() != null)
                                result = Comm.ExecuteScalar().ToString();
                        }
                        catch (Exception error)
                        {
                            throw error;
                        }
                        finally
                        {
                            newConn.Close();
                            Response.Write("<font color=red>操作完成!请检查数据库!</font>");
                        }
                    }
                }
      

  3.   

    int i=tww.ExecuteDataSet("Insert Into News(Title,Content,Datetime,Kind)Values('" + sguestTitle + "','" + sguestContent + "' ,'" + System.DateTime.Now.ToString() + "', '" + sguestkind + "')", CommandType.Text, false); if(i>0)
    {
    提示成功
    }
    else
    {
    提示失败
    }
      

  4.   

                返回值如楼上所讲,
    至于加脚本提示:
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "key", "var con=confirm('想要继续添加么?'); if (con==true) {你的代码;}", true);