手动绑定GridView数据源
protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){BindData();}}privatev...
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
string ConStr="data source=xhjj;user=gl;password=gl;";
OracleConnection MyCon = new OracleConnection(ConStr);
string QueryStr = "SELECT customerid,CompanyName,ContactName,Address FROM customers"; OracleDataAdapter Da = new OracleDataAdapter(QueryStr, MyCon);
DataSet Ds = new DataSet();
Da.Fill(Ds, "Customers");
GridView1.DataSource = Ds.Tables[0];
GridView1.DataKeyNames = new string[] { "customerid" };
GridView1.DataBind();
}
运行了,没出错,但显示空白(我的数据库有数据),不知什么原因,求教!
感谢qinsncn的回复,但调试过,不成功,仍然没有数据显示。 展开
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
string ConStr="data source=xhjj;user=gl;password=gl;";
OracleConnection MyCon = new OracleConnection(ConStr);
string QueryStr = "SELECT customerid,CompanyName,ContactName,Address FROM customers"; OracleDataAdapter Da = new OracleDataAdapter(QueryStr, MyCon);
DataSet Ds = new DataSet();
Da.Fill(Ds, "Customers");
GridView1.DataSource = Ds.Tables[0];
GridView1.DataKeyNames = new string[] { "customerid" };
GridView1.DataBind();
}
运行了,没出错,但显示空白(我的数据库有数据),不知什么原因,求教!
感谢qinsncn的回复,但调试过,不成功,仍然没有数据显示。 展开
2个回答
展开全部
private void BindData()
{
string ConStr="data source=xhjj;user=gl;password=gl;";
OracleConnection MyCon = new OracleConnection(ConStr);
string QueryStr = "SELECT customerid,CompanyName,ContactName,Address FROM customers";
OracleDataAdapter Da = new OracleDataAdapter(QueryStr, MyCon);
DataSet Ds = new DataSet();
Da.Fill(Ds, "Customers");
GridView1.DataSource = Ds.Tables["Customers"].DefaultView; //修改这句
GridView1.DataKeyNames = new string[] { "customerid" };
GridView1.DataBind();
}
{
string ConStr="data source=xhjj;user=gl;password=gl;";
OracleConnection MyCon = new OracleConnection(ConStr);
string QueryStr = "SELECT customerid,CompanyName,ContactName,Address FROM customers";
OracleDataAdapter Da = new OracleDataAdapter(QueryStr, MyCon);
DataSet Ds = new DataSet();
Da.Fill(Ds, "Customers");
GridView1.DataSource = Ds.Tables["Customers"].DefaultView; //修改这句
GridView1.DataKeyNames = new string[] { "customerid" };
GridView1.DataBind();
}
展开全部
OracleConnection MyCon = new OracleConnection(ConStr);
//加一句
MyCon.Open();
string QueryStr = "SELECT customerid,CompanyName,ContactName,Address FROM customers"; OracleDataAdapter Da = new OracleDataAdapter(QueryStr, MyCon);
//加一句
MyCon.Open();
string QueryStr = "SELECT customerid,CompanyName,ContactName,Address FROM customers"; OracleDataAdapter Da = new OracleDataAdapter(QueryStr, MyCon);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询