日期:2014-05-18  浏览次数:20505 次

.net提交问题
protected void btnSubmit_Click(object sender, EventArgs e)
  { 
   
  if (txtcontant.ToString() == null)
  {
  Alert("请填写随访内容!");
  }
  else if (txtresults.ToString() == null)
  {
  Alert("请填写随访结果!");
  }
  else
  {
  HypertensionFollowupItem hyp = new HypertensionFollowupItem();
  hyp.Followupcontent = this.txtcontant.ToString();
  hyp.Followupresults = this.txtresults.ToString();
  Updatefollowup(hyp);
  }
  }

  public static int ExecuteNonQuery(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
  {
  string connectionString = ConfigurationManager.ConnectionStrings["db_health"].ConnectionString;
  SqlConnection conn = new SqlConnection(connectionString);
  conn.Open();
  SqlCommand cmd = new SqlCommand();
  int val = cmd.ExecuteNonQuery();
  cmd.Parameters.Clear();
  return val;
  }

  public static int Updatefollowup(int upuserid)
  {
  HypertensionFollowupItem Hyper = new HypertensionFollowupItem();
  string sql = " update health_user_hypertension_followup set followupcontent=@followupcontent,followupresults=@followupresults where user_id=@upuserid";
  SqlParameter[] ps ={
  new SqlParameter("@followupcontent",Hyper.Followupcontent),
  new SqlParameter("@followupresults",Hyper.Followupresults)
  };
  return ExecuteNonQuery(CommandType.Text,sql,ps);

  }

 btnSubmit_Click中else应该如何接受从页面输入的数值?然后传入方法并执行,我上面的写法有没有什么问题?

------解决方案--------------------
C# code

 SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=(数据库);Integrated Security=True");

protected void btnSubmit_Click(object sender, EventArgs e)
  {  
    
  string strcontant= this.txtcontant.ToString();
  string strresults= this.txtresults.ToString();
  int  upuserid=“不知道等于什么”;
  Updatefollowup(strcontant,strresults);
  }



 /// <summary>
       /// <summary>
        /// 执行一条SQL语句,并返回受影响的记录条数
        /// </summary>
        /// <param name="strSql"></param>
        /// <returns></returns>
        public int intExecuteSql(string strSql)
        {      
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(strSql, conn);
                int intCount = cmd.ExecuteNonQuery();
                return intCount;
            }
            catch (Exception e)
            {

                throw e;
            }
            finally
            {
                conn.Close();
            }
        }

public int Updatefollowup(string strcontant,string strresults,int upuserid)
{
string sql = " update health_user_hypertension_followup set followupcontent=’”+strcontant+“‘,followupresults=’”+strcontant+“‘,where user_id=’”+upuserid+“‘";

intExecuteSql(sql);

}

------解决方案--------------------
txtcontant.ToString() == null
都能.ToString()了就不用再判断==null
应该是这样
if(txtcontant.Text.Trim().Length > 0)
要不要.Trim()看需求