if (!Page.IsPostBack)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString; string sqlstr = " Select username from User "; SqlCommand Com = new SqlCommand(sqlstr, conn); Com.Connection.Open();
SqlDataReader dr= Com.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataSource = dr;
GridView1.DataBind(); Com.Dispose();
conn.Dispose(); }总是说我User附近有语法错误...和解...这么简单的句子都能错?
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString; string sqlstr = " Select username from User "; SqlCommand Com = new SqlCommand(sqlstr, conn); Com.Connection.Open();
SqlDataReader dr= Com.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataSource = dr;
GridView1.DataBind(); Com.Dispose();
conn.Dispose(); }总是说我User附近有语法错误...和解...这么简单的句子都能错?
Select [username] from [User]
嘻嘻,C#里的user是关键字
但是我认为加上[user]应该也表示是关键字吧!