我想更新数据库中的值,但是它不起作用. [英] I want to update a value in my database but it is not working.

查看:94
本文介绍了我想更新数据库中的值,但是它不起作用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于GridView中所做的选择来更新数据库中的值. GridView上有信息,还有一个复选框,我使用该复选框将相应的值更新为该复选框. GridView包含使用业务逻辑层返回的图像,我们不使用对象数据源配置Gridview,而是使用代码来实现.

以下是我用于使用业务逻辑层进行更新的代码

I want update a value in my database based on a selection that was made in a GridView. The GridView has information on it and a checkbox that I use to update the corresponding value to the checkbox. The GridView has images that are returned using the business logic layer and we don''t configure the gridview with an object datasource but we do it with code.

Below is the code that I use to update using the business logic layer

protected void Page_Load(object sender, EventArgs e)
       {
           Business_Logic.Ballot objc = new Business_Logic.Ballot();
           GridView1.DataSource = objc.CandidateInfo();
           GridView1.DataBind();
       }
protected void btnsubmit_Click(object sender, EventArgs e)
       {


           for (int i = 0; i < GridView1.Rows.Count; i++)
           {
               CheckBox chkselect = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chkselect");
               if (chkselect != null)
               {
                   if (chkselect.Checked)
                   {
                       string  idca = GridView1.Rows[i].Cells[0].Text;
                       {
                           Business_Logic.CastVote objc = new Business_Logic.CastVote();
                           objc.candidate_id =Convert .ToInt32( idca);
                           objc.SubmitBallot();
                       }
                   }
               }
           }





namespace Business_Logic
{
    public class CastVote
    {
        public Int32 candidate_id { get; set; }
        public string username { get; set; }
        public string date { get; set; }

        public CastVote()
        {
            candidate_id = 0;
            username = string.Empty;
            date = string.Empty;
        }

        public CastVote(Int32 _cast, string _username, string _date)
        {
            candidate_id = _cast;
            username = _username;
            date = _date;
        }

        public void SubmitBallot()
        {
            csDAL objdal = new csDAL();
            List<csparameterlisttype> objlist = new List<csparameterlisttype>();
            objlist.Add(new csParameterListType("@candidate_id", System.Data.SqlDbType.Int, candidate_id));
            objlist.Add(new csParameterListType("@Usernames", System.Data.SqlDbType.Char, username));
            objlist.Add(new csParameterListType("@standingyear", System.Data.SqlDbType.VarChar, date));
            objdal.executespreturnnd("update_total", objlist);
        }
    }
}
</csparameterlisttype></csparameterlisttype>



删除了文本格式.



Removed Text Formatting.

推荐答案

只是一个猜测,但是SP是否需要有效的@Usernames@standingyear参数?您没有在objc对象上设置属性.
Just a guess, but does the SP require valid @Usernames and @standingyear parameters? You''re not setting the properties on your objc object.


这篇关于我想更新数据库中的值,但是它不起作用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆