0
我想從多個SqlDatabase表中選擇多個列來綁定具有唯一數據值字段的DropDownLists。從多個Sql Tables中綁定下拉列表與唯一數據值字段?
這裏是類SqlQuery我的C#代碼從表1選擇多列:
// Create a dropdownlist inside the dynamically created panel and insert in the 1st row 1st cell of dynamic html table
var DDL = new WebForms.DropDownList();
DDL.ID = "MainDDL";
SqlDataSource da = new SqlDataSource();
da.ConnectionString = connection;
string item = "--Select--";
da.SelectCommand = "SELECT DATA_TYPE + '_' + convert(varchar(10), ROW_NUMBER() OVER(ORDER BY DATA_TYPE))as DATA_TYPE, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_NAME = 'MyTable1' AND COLUMN_NAME IN ('Column1','Column2','Column3','Column4','Column5'))";
DDL.DataSource = da;
DDL.DataTextField = "COLUMN_NAME";
DDL.DataValueField = "DATA_TYPE";
DDL.DataBind();
解決方案所需:從多個SQL表選擇 多列:
如何從Mytable2中選擇column1也在下面的Sql查詢中
SELECT DATA_TYPE +'_'+ convert(varchar(10),ROW_NUMBER()OVER(ORDER BY DATA_TYPE))as DATA_TYPE,COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE(TABLE_NAME ='MyTable1'AND COLUMN_NAME IN('Column1','Column2 」, '欄3', 'Column4', 'Column5'))
謝謝你做到了!接受你的答案 – Shrivatsan