作业帮 > 综合 > 作业

系统报错:嵌入的语句不能是声明或标记语句

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/04/28 19:18:14
系统报错:嵌入的语句不能是声明或标记语句
SqlConnection下有波浪线提示“嵌入的语句不能是声明或标记语句”
代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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)
{
if(!IsPostBack)
SqlConnection conn = new SqlConnection("Data Source=7F78D182F8FA464;Initial Catalog=Vote;Persist Security Info=True;User ID=sa;Password=19821231");//建立连接对象
string strSql = "select * from Item where parentid=1";
SqlDataAdapter sda=new SqlDataAdapter(strSql,conn);
DataSet ds = new DataSet();
sda.Fill(ds,"Item");
RadioButtonList1.DataSource=ds;
RadioButtonList1.DataTextField="ItemName";
RadioButtonList1.DataTextField="id";
RadioButtonList1.DataBind();
}
}
系统报错:嵌入的语句不能是声明或标记语句
if(!IsPostBack)
后面一定要跟大括号,别学他们简写,这样习惯很不好!
if(!IsPostBack)
{
SqlConnection conn = new SqlConnection("Data Source=7F78D182F8FA464;Initial Catalog=Vote;Persist Security Info=True;User ID=sa;Password=19821231");//建立连接对象
string strSql = "select * from Item where parentid=1";
SqlDataAdapter sda=new SqlDataAdapter(strSql,conn);
DataSet ds = new DataSet();
sda.Fill(ds,"Item");
RadioButtonList1.DataSource=ds;
RadioButtonList1.DataTextField="ItemName";
RadioButtonList1.DataTextField="id";
RadioButtonList1.DataBind();
}