麻烦大家帮我看一下这个,列名无效是怎么回事??
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");
}
}
}