回 帖 发 新 帖 刷新版面

主题:为什么你总是选择失败?

private void Button1_Click(object sender, System.EventArgs e)
        {
    
            string user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString();             
            System.DateTime currentTime=new System.DateTime(); 
            string strYMD=currentTime.ToString("D"); 
            string strT=currentTime.ToString("t"); 
            string strSql="insert into SignUser(WorkNumber,workType1,Time,Ip,Date) values('" + TextBox1.Text.Trim() +"','"+DropDownList1.SelectedItem.Text +"','"+ strT +"','"+ user_IP +"','"+ strYMD +"')";
            OleConnString = new OleDbConnection(strOleSqlConn);
            Response.Write(strSql);
            OleDbCommand OleComm = new OleDbCommand(strSql,OleConnString);            
            OleConnString.Open();
            Response.Write(OleComm.ExecuteNonQuery());
            try
            {
                if(OleComm.ExecuteNonQuery()>0)
                {
                    Response.Write("<script language=javascript>alert('签到成功!');</script>");
                }
                else
                {
                    Response.Write("<script language=javascript>alert('签到失败!');</script>");                    
                }              
            }
            catch
            {
                Response.Write("<script language=javascript>alert('签到失败!');</script>");
            }
            finally
            {
                OleConnString.Close();              
            }    

        
        }//请各位高手看看我的程序为什么总是走到catch语句

回复列表 (共1个回复)

沙发

private void Button1_Click(object sender, System.EventArgs e)
        {
    
            string user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString();             
            System.DateTime currentTime=new System.DateTime(); 
            string strYMD=currentTime.ToString("D"); 
            string strT=currentTime.ToString("t"); 
            string strSql="insert into SignUser(WorkNumber,workType1,Time,Ip,Date) values('" + TextBox1.Text.Trim() +"','"+DropDownList1.SelectedItem.Text +"','"+ strT +"','"+ user_IP +"','"+ strYMD +"')";
            OleConnString = new OleDbConnection(strOleSqlConn);
            Response.Write(strSql);
            OleDbCommand OleComm = new OleDbCommand(strSql,OleConnString);            
            OleConnString.Open();
            try
            {
                int re=OleComm.ExecuteNonQuery();
                Response.Write(re);
                if(re>0)
                {
                    Response.Write("<script language=javascript>alert('签到成功!');</script>");
                }
                else
                {
                    Response.Write("<script language=javascript>alert('签到失败!');</script>");                    
                }              
            }
            catch
            {
                Response.Write("<script language=javascript>alert('签到失败!');</script>");
            }
            finally
            {
                OleConnString.Close();              
            }    

        
        }

我来回复

您尚未登录,请登录后再回复。点此登录或注册