string strSQL = "select B.speSpec ,C.plvname ,A.eetYear from tblEmployeeTech A,tblSpeciality B,tblpostLevel C where A.eetTech = B.speCode and A.eetTechRank = C.plvCode"SqlConnection myConnection = new SqlConnection("server=(local);database=database;uid=sa;pwd=ee");
SqlDataAdapter myCommand = new SqlDataAdapter(strSQL , myConnection); DataSet ds = new DataSet();
myCommand.Fill(ds, "tt"); MyDataGrid.DataSource=ds.Tables["tt"].DefaultView;
MyDataGrid.DataBind();
SqlDataAdapter myCommand = new SqlDataAdapter(strSQL , myConnection); DataSet ds = new DataSet();
myCommand.Fill(ds, "tt"); MyDataGrid.DataSource=ds.Tables["tt"].DefaultView;
MyDataGrid.DataBind();
最重要的是建立和数据库的链接,然后就是执行你的SQL语句
还有一方法,就是讲该SQL语句写入存储过程返回参数为DATASET,DATAVIEW或者DATATABLE都可以,然后写执行存储过程的方法,然后对DATAGRID 帮定
dsCommand.SelectCommand = new SqlCommand( strSQL, myConnection );
DataSet dataSet = new DataSet();
dsCommand.Fill( dataSet );
***********************************
this.dataGrid.DataSource = this.dataSet;
MyDataGrid.DataBind();
strSQL = strSQL + this.Session["RegOrgn"].ToString()+ "'";
OleDbConnection Connection = new OleDbConnection(strConnect);
OleDbDataAdapter da = new OleDbDataAdapter(strSQL,Connection);
DataSet ds = new DataSet();
da.Fill(ds,"tt");
DataGrid1.DataSource = ds.Tables["tt"].DefaultView;
DataGrid1.DataBind();
Connection.Close();
da.Dispose();
ds.Dispose();
Connection.Dispose();这一段有没错啊,可我还是看不道数据,为什么呢?
你在这设一个断点,看看strSQL是什么,然后在sql里执行一下,对不对
谢谢各位!