说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误消息: CS0201: 只有 assignment、call、increment、decrement 和 new 对象表达式可用作语句
源错误:
行 16: {
行 17: SqlConnection con =DB.createConnetion();
行 18: con.Open;
行 19: SqlCommand cmd = new SqlCommand("select * form plike", con);
行 20: SqlDataReader sdr= cmd.ExecuteReader();
源文件: d:\myone\Default.aspx.cs 行: 18
源文件如下:
using System;
using System.Collections;
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con =DB.createConnetion();
con.Open;
SqlCommand cmd = new SqlCommand("select * form plike", con);
SqlDataReader sdr= cmd.ExecuteReader();
this.List1.DataTextField = "plikecontent";
this.List1.DataValueField = "id";
this.List1.DataSource = sdr;
this.List1.DataBind();
sdr.Close;
con.Close;
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{ }}
那里出错了呢?请大侠给小弟看看啊!!
using System;
我建了一个DB的连接类:
using System.Data;
using System.Data.SqlClient;
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;
///
/// DB 的摘要说明
///
public class DB
{
public DB()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static SqlConnection createConnetion()
{
System.Data.SqlClient.SqlConnection con = new SqlConnection("server=.;database=login;uid=sa;pwd=;");
return con;
}
}
那位大侠教教小弟啊!