当前位置:编程学习 > C#/ASP.NET >>

我想实现查询伪码的显示真伪的同时显示此伪码已经被查询了几次,总报错“无法将类型object隐式转换为bool”

 





protected void Page_Load(object sender, EventArgs e)

    {

    }

         protected void submit_Click(object sender, EventArgs e)
    {
        string connStr = @"Server=数码10\SQLEXPRESS;Database=demo;Persist Security Info=True;User ID=sa;Password=123";//链接数据库
        using (SqlConnection conn = new SqlConnection(connStr))
        {
            conn.Open(); 
            string strsql1 = "select * from Security_code where valid=1 ";
            SqlDataAdapter da = new SqlDataAdapter(strsql1, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "table");
            int j;
            if (ds.Tables[0].Rows[0]["times"] = DBNull.Value)
                j = 0;
            else j = Convert.ToInt32(ds.Tables[0].Rows[0]["times"]) + 1;
   
            if (ds.Tables[0].Rows.Count > 0)
            {
                string commandText = "update Security_code set times =" + j; // (Convert.ToInt32(ds.Tables[0].Rows[times]) + 1);
                //string commandText = "update Security_code set times = (Convert.ToInt32(ds.Tables[0].Rows[times]) + 1)";
                SqlCommand command = new SqlCommand(commandText, conn);
                command.ExecuteNonQuery(); 
            }
        }

       

        String queryCode = this.code.Text.ToString().Trim();
        string parrent = "^([0-9]{4})([0-9]{4})([0-9]{4})([0-9]{4})$";
        if (!Regex.IsMatch(queryCode, parrent))
        {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   this.ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script language ='javascript'>alert('输入的防伪码格式不正确!');</script>");
            return;

        }
        queryCode = queryCode.Replace("-", "");
        string sqlcode = NewCompileCode.TransformSqlCode(queryCode);
        int i = ConnectionSql.queryCode(sqlcode); 
        if (i!=0)
        this.ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script language ='javascript'>alert('该防伪码无效');</script>"); 
        else 
        this.ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script language ='javascript'>alert('有效的防伪码');</script>"); 
    }
   
}
--------------------编程问答--------------------  int j;
  if (ds.Tables[0].Rows[0]["times"] = DBNull.Value)
  j = 0;
  else j = Convert.ToInt32(ds.Tables[0].Rows[0]["times"]) + 1;
    
  if (ds.Tables[0].Rows.Count > 0)
  {
  string commandText = "update Security_code set times =" + j; // (Convert.ToInt32(ds.Tables[0].Rows[times]) + 1);
  //string commandText = "update Security_code set times = (Convert.ToInt32(ds.Tables[0].Rows[times]) + 1)";


==>
string commandText = "update Security_code set times =isnull(times ,0) + 1 Where valid="+ xxxid 
--------------------编程问答--------------------
引用 1 楼 liuchaolin 的回复:
int j;
  if (ds.Tables[0].Rows[0]["times"] = DBNull.Value)
  j = 0;
  else j = Convert.ToInt32(ds.Tables[0].Rows[0]["times"]) + 1;
   
  if (ds.Tables[0].Rows.Count > 0)
  {
  string commandTex……
什么意思 --------------------编程问答-------------------- if (ds.Tables[0].Rows[0]["times"] = DBNull.Value)   是2个等于号吧 --------------------编程问答-------------------- 断点一下就能看的到啊。。。唉


应该是这个问题。结贴咯。。。。 --------------------编程问答-------------------- 断点走一下
(Convert.ToInt32(ds.Tables[0].Rows[times]) + 1);
改为
(Convert.ToInt32(ds.Tables[0].Rows["times"]) + 1);
--------------------编程问答--------------------
引用 4 楼 yue547283947 的回复:
断点一下就能看的到啊。。。唉


应该是这个问题。结贴咯。。。。

结什么贴啊一直没解决呢好不
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,