| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1085 人关注过本帖
标题:麻烦大家帮我看一下这个,列名无效是怎么回事??
取消只看楼主 加入收藏
aiyinsitan
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:183
专家分:177
注 册:2010-4-22
结帖率:89.47%
收藏
已结贴  问题点数:20 回复次数:3 
麻烦大家帮我看一下这个,列名无效是怎么回事??
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            RadioButtonList1.DataSource = GetDs(1);
            RadioButtonList1.DataTextField = "ItemName";
            RadioButtonList1.DataValueField = "id";
            RadioButtonList1.DataBind();
            RadioButtonList2.DataSource = GetDs(2);
            RadioButtonList2.DataTextField = "ItemName";
            RadioButtonList2.DataBind();
            CheckBoxList1.DataSource = GetDs(1);
            CheckBoxList1.DataTextField = "ItemName";
            CheckBoxList1.DataBind();
            
        }

    }
    /// <summary>
    /// 返回制定parent的ds
    /// </summary>
    /// <param name="parentid"></param>
    /// <returns></returns>
    protected DataSet GetDs(int parentid)
    {
        SqlConnection conn = new SqlConnection("Data Source=PC-201009101252;Initial catalog=Vote;Persist Security Info=True;User ID=sa;Password=123;");//建立与数据库连接
        string strSql = string.Format("select * from Item where parentid={0}",parentid);
        SqlDataAdapter sda = new SqlDataAdapter(strSql, conn);
        DataSet ds = new DataSet();
        sda.Fill(ds, "Item");
        return ds;
        
    }
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int id = 0;
        try
        {
            id = Convert.ToInt32(RadioButtonList1.SelectedValue);
        }
        catch
        {
            id = 0;
        }
        SqlConnection conn = new SqlConnection("Data Source=PC-201009101252;Initial catalog=Vote;Persist Security Info=True;User ID=sa;Password=123;");//建立与数据库连接
        string strSql = string.Format("update Item set VoteName=VoteName+1 where id={0}", id);
        SqlCommand cmd = new SqlCommand(strSql, conn);
        conn.Open();
        int i = cmd.ExecuteNonQuery();
        conn.Close();
        if (i > 0)
        {
            YYCMS.Jscript.AlertAndRedirect("投票成功!", "VoteList.aspx");
        }

        else
        {
            YYCMS.Jscript.AlertAndRedirect("投票失败!", "VoteList.aspx");
        }

    }
    protected void  Button2_Click(object sender, EventArgs e)
{
       int id = 0;
        try
        {
            id = Convert.ToInt32(RadioButtonList2.SelectedValue);
        }
        catch
        {
            id = 0;
        }
        SqlConnection conn = new SqlConnection("Data Source=PC-201009101252;Initial catalog=Vote;Persist Security Info=True;User ID=sa;Password=123;");//建立与数据库连接
        string strSql = string.Format("update Item set VoteName=VoteName+1 where id={0}", id);
        SqlCommand cmd = new SqlCommand(strSql, conn);
        conn.Open();
        int i = cmd.ExecuteNonQuery();
        conn.Close();
        if (i > 0)
        {
            YYCMS.Jscript.AlertAndRedirect("投票成功!", "VoteList.aspx");
        }

        else
        {
            YYCMS.Jscript.AlertAndRedirect("投票失败!", "VoteList.aspx");
        }


}
    protected void Button3_Click(object sender, EventArgs e)
    {
        string idstr = "0";
        foreach (ListItem li in CheckBoxList1.Items)
        {
            if (li.Selected)
            {
                idstr += "," + li.Value;
            }
        }
        idstr += ",0";
        SqlConnection conn = new SqlConnection("Data Source=PC-201009101252;Initial catalog=Vote;Persist Security Info=True;User ID=sa;Password=123;");//建立与数据库连接
        string strSql = string.Format("update Item set VoteName=VoteName+1 where id in({0})", idstr);
        SqlCommand cmd = new SqlCommand(strSql, conn);
        conn.Open();
        int i = cmd.ExecuteNonQuery();
        conn.Close();
        if (i > 0)
        {
            YYCMS.Jscript.AlertAndRedirect("投票成功!", "VoteList.aspx");
        }

        else
        {
            YYCMS.Jscript.AlertAndRedirect("投票失败!", "VoteList.aspx");
        }


    }
}
搜索更多相关主题的帖子: 麻烦 列名 
2010-09-13 21:00
aiyinsitan
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:183
专家分:177
注 册:2010-4-22
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
2010-09-13 21:04
aiyinsitan
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:183
专家分:177
注 册:2010-4-22
收藏
得分:0 
上面是运行时候出错提示
2010-09-13 21:05
aiyinsitan
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:183
专家分:177
注 册:2010-4-22
收藏
得分:0 
是int型,我本来想写个VoteNUM 写错了写成Votename
2010-09-13 22:33
快速回复:麻烦大家帮我看一下这个,列名无效是怎么回事??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019033 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved