菜鸟问题 :Datagrid显示数据库里面的数据

菜鸟问题 :Datagrid显示数据库里面的数据 - 故障解答 - 电脑教程网

菜鸟问题 :Datagrid显示数据库里面的数据

日期:2007-01-10   荐:
菜鸟问题 :Datagrid显示数据库里面的数据用Datagrid 显示Staff表,Staff表中的一列是Dep(部门)是和另外的Department表相联系,在staff表中Dep(部门)列是Department表中ID,Department表有两列(ID,Depname) ,当Datagrid显示Staff表时,怎样在Dep列中显示Department表中和ID相对应的Depname。"provider=sqloledb;data source=服务器ip地址;uid=用户名;pwd=密码;database=数据库名"SELECT Department.DepnameFROM Staff INNER JOIN Department ON Staff.Dep = Department.Depname去视图里边写SQL语句很简单.Select A.Dep,B.Depname from Staff A inner jion Department B on A.Dep=B.ID对你的表结构还不是很清楚,大致如此select Staff.* B.Depname ,C.Depname from Staff,Dep as B,Dep as c where ....SQL语句的问题好好看看T—SQL吧谢谢大家Select A.Dep,B.Depname from Staff A inner jion Department B on A.Dep=B.ID我用的是Asp.Net(VB.Net) ,这一句好像不对Dim connection As String = ConfigurationSettings.AppSettings("ST2000") Dim myconnection As New SqlConnection(connection) Dim selectstring As String = "select A.ID,A.ConnectionType,A.COMPort,A.IP,A.Modem,B.CompanyName,A.Place,A.DLType,A.DLInterval,A.Memo from MstTimeRecorder A inner join MstCompany B ON MstTimeRecorder.companyID = Mstcompany.ID where Valid='0'" Dim mycommand As New SqlDataAdapter(selectstring, myconnection) Dim ds As New DataSet mycommand.Fill(ds, "MstTimeRecorder") DataGrid1.DataSource = ds.Tables(0).DefaultView DataGrid1.DataBind() myconnection.Close()大家看看有什么地方写错了
标签: