ToTable方法,列不属于基础表,怎么回事?
代码:
Dim Sb As StringBuilder = New StringBuilder("Select NAME,OL_NBR,SO_DATE,ORDER_CODE,CUST_NAME,ACC_NBR,ADDR_NAME,CONTACT_NAME,CONTACT_NBR,ORDER_STATE from V_dl_Lottory ")
'Response.Write(Sb.ToString())
'Response.End()
Dim Cn As OleDbConnection = New OleDbConnection(StrCon)
Dim Da As OleDbDataAdapter = New OleDbDataAdapter(Sb.ToString(), Cn)
Dim Ds As DataSet = New DataSet()
Cn.Open()
Da.Fill(Ds, "Res")
Cn.Close()
Dim Dt As DataTable = Ds.Tables.Add("View")
Dt = Ds.Tables("Res").DefaultView.ToTable(True, "NAME,OL_NBR,SO_DATE,ORDER_CODE,CUST_NAME,ACC_NBR,ADDR_NAME,CONTACT_NAME,CONTACT_NBR,ORDER_STATE")
GridView1.DataSource = Ds.Tables("View").DefaultView
GridView1.DataBind()
结果报错:列“NAME,OL_NBR,SO_DATE,ORDER_CODE,CUST_NAME,ACC_NBR,ADDR_NAME,CONTACT_NAME,CONTACT_NBR,ORDER_STATE”不属于基础表“Res”。
------最佳解决方案--------------------ToTable方法后面的参数必须是原DataTable里存在的列名,你必须写成Dt = Ds.Tables("Res").DefaultView.ToTable(True, "列名1","列名2","列名n");这种形式,即一个列名对应一个字符串。
------其他解决方案--------------------人家需要数组,你那个不行,好好看看帮助
DataTable newTable = view.ToTable(true, "Category", "QuantityInStock");