C# 为什么我的ASP.NET项目没有';我什么也不做?
我正试图编写一个项目来显示C# 为什么我的ASP.NET项目没有';我什么也不做?,c#,asp.net,sql-server,ado.net,C#,Asp.net,Sql Server,Ado.net,我正试图编写一个项目来显示MMABooks数据库中两个表中的一些数据。这些代码在C#中工作,但在ASP.Net中不工作。事实上,它没有任何作用,我也没有得到任何错误!为什么?有什么问题 string connectionString = "Data Source=localhost\\SqlExpress;" + "Initial Catalog=MMABooks;Integrated Security=True"; SqlConnection connecti
MMABooks
数据库中两个表中的一些数据。这些代码在C#中工作,但在ASP.Net中不工作。事实上,它没有任何作用,我也没有得到任何错误!为什么?有什么问题
string connectionString = "Data Source=localhost\\SqlExpress;" +
"Initial Catalog=MMABooks;Integrated Security=True";
SqlConnection connection = new SqlConnection(connectionString);
string selectStatement = "SELECT Customers.Name, Customers.City, States.StateName " +
"FROM Customers " +
"INNER JOIN States " +
"ON Customers.State = States.StateCode " +
"WHERE Name LIKE @Name";
SqlCommand SelectCommand = new SqlCommand(selectStatement, connection);
SelectCommand.Parameters.AddWithValue("@Name", TextBox1.Text.Trim() + "%");
connection.Open();
var dataAdapter = new SqlDataAdapter(SelectCommand);
DataTable dt = new DataTable();
dataAdapter.Fill(dt);
GridView1.DataSource = dt;
您需要ASP.NET中的,它将数据源绑定到最后一行之后的GridView
GridView1.DataSource = dt;
GridView1.DataBind();
您需要ASP.NET中的,它将数据源绑定到最后一行之后的GridView
GridView1.DataSource = dt;
GridView1.DataBind();
缺少
GridView1.DataSource=dt
AfterGridView1.DataSource=dt代码>
string connectionString = "Data Source=localhost\\SqlExpress;" +
"Initial Catalog=MMABooks;Integrated Security=True";
SqlConnection connection = new SqlConnection(connectionString);
string selectStatement = "SELECT Customers.Name, Customers.City, States.StateName " +
"FROM Customers " +
"INNER JOIN States " +
"ON Customers.State = States.StateCode " +
"WHERE Name LIKE @Name";
SqlCommand SelectCommand = new SqlCommand(selectStatement, connection);
SelectCommand.Parameters.AddWithValue("@Name", TextBox1.Text.Trim() + "%");
connection.Open();
var dataAdapter = new SqlDataAdapter(SelectCommand);
DataTable dt = new DataTable();
dataAdapter.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();//you are missing this
缺少GridView1.DataSource=dt
AfterGridView1.DataSource=dt代码>
string connectionString = "Data Source=localhost\\SqlExpress;" +
"Initial Catalog=MMABooks;Integrated Security=True";
SqlConnection connection = new SqlConnection(connectionString);
string selectStatement = "SELECT Customers.Name, Customers.City, States.StateName " +
"FROM Customers " +
"INNER JOIN States " +
"ON Customers.State = States.StateCode " +
"WHERE Name LIKE @Name";
SqlCommand SelectCommand = new SqlCommand(selectStatement, connection);
SelectCommand.Parameters.AddWithValue("@Name", TextBox1.Text.Trim() + "%");
connection.Open();
var dataAdapter = new SqlDataAdapter(SelectCommand);
DataTable dt = new DataTable();
dataAdapter.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();//you are missing this