是否需要创建SqlDataSource将数据绑定到gridview [英] Is there need to create SqlDataSource to bind data to gridview

查看:62
本文介绍了是否需要创建SqlDataSource将数据绑定到gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据绑定到gridview,我该怎么做......

i want to bind data to gridview how should i do it......

推荐答案

受保护的空白Page_Load(object sender,EventArgs e)
{
如果(!Page.IsPostBack)
{
字符串connectionString ="server = SYS2;" +集成安全性= SSPI;" +
"database = ERPFinAccounting";
SqlConnection myConnection;
字符串str_Account_Select ="SELECT * FROM AccountsTable";
SqlCommand myCommand;
DataSet myDataSet;
myConnection =新的SqlConnection(connectionString);
myConnection.Open();
myCommand =新的SqlCommand(str_Account_Select,myConnection);
SqlDataAdapter mySQLDataAdapter;
myDataSet = new DataSet();
mySQLDataAdapter =新的SqlDataAdapter(myCommand);
mySQLDataAdapter.Fill(myDataSet,"AccountsTable");
GridView1.DataSource = myDataSet;
GridView1.DataBind();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string connectionString = "server=SYS2;" + "integrated security=SSPI;" +
"database=ERPFinAccounting";
SqlConnection myConnection;
string str_Account_Select = "SELECT * FROM AccountsTable";
SqlCommand myCommand;
DataSet myDataSet;
myConnection = new SqlConnection(connectionString);
myConnection.Open();
myCommand = new SqlCommand(str_Account_Select, myConnection);
SqlDataAdapter mySQLDataAdapter;
myDataSet = new DataSet();
mySQLDataAdapter = new SqlDataAdapter(myCommand);
mySQLDataAdapter.Fill(myDataSet, "AccountsTable");
GridView1.DataSource = myDataSet;
GridView1.DataBind();
}
}


这篇关于是否需要创建SqlDataSource将数据绑定到gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆