主题:求助
利用GridView显示记录:
第一种
DataSet ds = new DataSet();
OleDbConnection conn=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F://网站//控件使用//App_Data//kongjian.mdb");
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from News";
OleDbDataAdapter myAdapter = new OleDbDataAdapter();
myAdapter.SelectCommand = cmd;
myAdapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
第二种
DataSet ds = new DataSet();
OleDbConnection conn=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F://网站//控件使用//App_Data//kongjian.mdb");
conn.open();
string sql="select * from News";
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
OleDbDataAdapter myAdapter = new OleDbDataAdapter();
myAdapter.SelectCommand = cmd;
myAdapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
第三种
DataSet ds = new DataSet();
string sql = "select * from News";
OleDbConnection conn = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F://网站//控件使 用//App_Data//kongjian.mdb");
OleDbDataAdapter myAdapter = new OleDbDataAdapter(sql,conn);
conn.Open();
myAdapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
以上三种绑定数据源时,连接数据库的区别,哪位兄弟详解一下?多谢了。。
第一种
DataSet ds = new DataSet();
OleDbConnection conn=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F://网站//控件使用//App_Data//kongjian.mdb");
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from News";
OleDbDataAdapter myAdapter = new OleDbDataAdapter();
myAdapter.SelectCommand = cmd;
myAdapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
第二种
DataSet ds = new DataSet();
OleDbConnection conn=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F://网站//控件使用//App_Data//kongjian.mdb");
conn.open();
string sql="select * from News";
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
OleDbDataAdapter myAdapter = new OleDbDataAdapter();
myAdapter.SelectCommand = cmd;
myAdapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
第三种
DataSet ds = new DataSet();
string sql = "select * from News";
OleDbConnection conn = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F://网站//控件使 用//App_Data//kongjian.mdb");
OleDbDataAdapter myAdapter = new OleDbDataAdapter(sql,conn);
conn.Open();
myAdapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
以上三种绑定数据源时,连接数据库的区别,哪位兄弟详解一下?多谢了。。