注册 登录
编程论坛 ASP.NET技术论坛

SQL2005问题

zore0 发布于 2008-10-05 12:49, 1245 次点击
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _vote : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(@"Data Source=localhost\SQLEXPRESS; database=select; uid=sa;pwd=;");
        con.Open();
        //查询选举的标题
        SqlCommand cmd=new SqlCommand ("select vo_title from vote where vo_id="+this.vo_id,con);
        string title = Convert.ToString(cmd.ExecuteScalar());
        this.Label1.Text = title;
        //查询对应的投票条目
        SqlCommand cmdItem = new SqlCommand("select vo_Item,vo_id from votedetails where vo_id=" + this.vo_id, con);
        SqlDataReader sdr = cmdItem.ExecuteReader();
        this.rdblist.DataSource = sdr;
        this.rdblist.DataTextField = "vo_title";
        this.rdblist.DataValueField = "vo_id";
        this.rdblist.DataBind();
        sdr.Close();
        con.Close();
    }
}
在运行上面这段代码时,出现“_vote”并不包含“vo_id”的定义
在表vote和votedetails中创建了vo_id这个字段,为什么还会出现 这样的字段,这是怎么回事,该怎样解决?
5 回复
#2
zsf20062008-10-05 19:32
select vo_Item,vo_id 两个字段和下面的要对应上
this.rdblist.DataTextField = "vo_title";
this.rdblist.DataValueField = "vo_id";

再检查下
#3
百灵鸟2008-10-09 20:20
SqlCommand cmd=new SqlCommand ("select vo_title from vote where vo_id="+this.vo_id,con);
这个句子中的变量this.vo_id你怎么没有定义
#4
smoon2008-10-09 21:18
实在不行你就select * from table试试
#5
bb38522008-10-10 10:37
就是没定义this.vo_id变量啊
#6
hebingbing2008-10-10 12:57
SqlCommand cmd=new SqlCommand ("select vo_title from vote where vo_id="+this.vo_id,con);
问题再红色显示部位……
1