namespace SubScribe
{
/**//// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class SubScribe : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dataGrid;
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
BindData();
}
public void BindData()
{
try
{
string cnString=ConfigurationSettings.AppSettings["Northwind"];
SqlConnection cn=new SqlConnection(cnString);
cn.Open();
string strQuery = "select CustomerID,CompanyName,Phone from Customers ";
SqlCommand cmd=new SqlCommand(strQuery,cn);
SqlDataReader reader=cmd.ExecuteReader();
while(reader.Read ())
{
Label1.Text=Label1.Text+reader["CustomerID"].ToString().Trim ()+"****";
}
int i;
string cnString=ConfigurationSettings.AppSettings["Northwind"];
SqlConnection cn=new SqlConnection(cnString);
cn.Open();
string strQuery = "select count(*) from Customers ";
SqlCommand cmd=new SqlCommand(strQuery,cn);
i=Convert.ToInt32(cmd.ExecuteScalar());
Label1.Text=Convert.ToString(i);
cn.Close();
string cnString=ConfigurationSettings.AppSettings["Northwind"];
SqlConnection cn=new SqlConnection(cnString);
/**///// cn.Open();
string strQuery = "select CustomerID,CompanyName,ContactName,Phone from Customers ";
SqlDataAdapter adapter=new SqlDataAdapter(strQuery,cn);
DataSet MyDataSet=new DataSet();
adapter.Fill(MyDataSet,"Customers");
DataView source=new DataView(MyDataSet.Tables ["Customers"]);
dataGrid.DataSource=source;
dataGrid.DataBind();
cn.Close();
}
catch
{
Response.Write("<Script>window.alert('查询数据库失败!')</Script>");
}
}
Web 窗体设计器生成的代码Web 窗体设计器生成的代码
private void dataGrid_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}
{
/**//// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class SubScribe : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dataGrid;
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
BindData();
}
public void BindData()
{
try
{
string cnString=ConfigurationSettings.AppSettings["Northwind"];
SqlConnection cn=new SqlConnection(cnString);
cn.Open();
string strQuery = "select CustomerID,CompanyName,Phone from Customers ";
SqlCommand cmd=new SqlCommand(strQuery,cn);
SqlDataReader reader=cmd.ExecuteReader();
while(reader.Read ())
{
Label1.Text=Label1.Text+reader["CustomerID"].ToString().Trim ()+"****";
}
int i;
string cnString=ConfigurationSettings.AppSettings["Northwind"];
SqlConnection cn=new SqlConnection(cnString);
cn.Open();
string strQuery = "select count(*) from Customers ";
SqlCommand cmd=new SqlCommand(strQuery,cn);
i=Convert.ToInt32(cmd.ExecuteScalar());
Label1.Text=Convert.ToString(i);
cn.Close();
string cnString=ConfigurationSettings.AppSettings["Northwind"];
SqlConnection cn=new SqlConnection(cnString);
/**///// cn.Open();
string strQuery = "select CustomerID,CompanyName,ContactName,Phone from Customers ";
SqlDataAdapter adapter=new SqlDataAdapter(strQuery,cn);
DataSet MyDataSet=new DataSet();
adapter.Fill(MyDataSet,"Customers");
DataView source=new DataView(MyDataSet.Tables ["Customers"]);
dataGrid.DataSource=source;
dataGrid.DataBind();
cn.Close();
}
catch
{
Response.Write("<Script>window.alert('查询数据库失败!')</Script>");
}
}
Web 窗体设计器生成的代码Web 窗体设计器生成的代码
private void dataGrid_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}