柱"从"不属于该表 [英] Column"From" does not belong to the table

查看:79
本文介绍了柱"从"不属于该表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文本框值填充到gridview。

列From不属于表格!

i am trying to populate textbox values to gridview.
Column "From" Does not belong to the table!

var dt=new DataTable();

            dt.Columns.Add("From");
            dt.Columns.Add("To");
            dt.Columns.Add("Area");
            dt.Columns.Add("Sector");
            dt.Columns.Add("CompanyName");
            dt.Columns.Add("Description");
            dt.Columns.Add("References");
            dt.Columns.Add("Tools");
            dt.Columns.Add("Technology");
            dt.Columns.Clear();
            
            if (Session["DataTable"] != null)
            {
                
                dt = (DataTable) Session["DataTable"];     
            }
           
            
            string sToolsValue = string.Empty;
            string sTechnologyvalue = string.Empty;
            DataRow dr = dt.NewRow();
          
            dr["From"] = TextBoxFrom.Text;
            dr["To"] = TextBoxTo.Text;
            dr["Area"] = TextBoxArea.Text;
            dr["Sector"] = TextBoxSector.Text;
            dr["CompanyName"] = TextBoxCompanyName.Text;
            dr["Description"] = TextBoxDescription.Text;
            dr["References"] = TextBoxReferences.Text;
            
            
            for (int i = 0; i < ListBoxAssignmentTools.Items.Count; i++)
            {

                sToolsValue += ListBoxAssignmentTools.Items[i];
                
            }

            for (int i = 0; i < ListBoxAssignmentTechnology.Items.Count; i++)
            {
                sTechnologyvalue += ListBoxAssignmentTechnology.Items[i];
                
            }
            dr["Tools"] = sToolsValue;
            dr["Technology"] = sTechnologyvalue;
            
            
            dt.Rows.Add(dr);
            Session["DataTable"] = dt;
            GridViewAllAssigments.DataSource = dt;
            GridViewAllAssigments.DataBind();

推荐答案

看看这里:DataTable Class( System.Data) [ ^ ]。

以上链接的部分示例:

Have a look here: DataTable Class (System.Data)[^].
Part of example from above link:
// Create a new DataTable.
    System.Data.DataTable table = new DataTable("ParentTable");
    // Declare variables for DataColumn and DataRow objects.
    DataColumn column;
    DataRow row;
 
    // Create new DataColumn, set DataType, 
    // ColumnName and add to DataTable.    
    column = new DataColumn();
    column.DataType = System.Type.GetType("System.Int32");
    column.ColumnName = "id";
    column.ReadOnly = true;
    column.Unique = true;
    // Add the Column to the DataColumnCollection.
    table.Columns.Add(column);
 
    // Create second column.
    column = new DataColumn();
    column.DataType = System.Type.GetType("System.String");
    column.ColumnName = "ParentItem";
    column.AutoIncrement = false;
    column.Caption = "ParentItem";
    column.ReadOnly = false;
    column.Unique = false;
    // Add the column to the table.
    table.Columns.Add(column);





你看到了区别吗?



Do you see the difference?


检查aspx中的网格控件页面 FROM 列的 DataField 拼写是否正确。希望它有所帮助.. CS文件代码很好



Check the Grid control in aspx page whether the DataField for FROM column is spelled correct or not. Hope it helps.. CS file code is good

<asp:GridView ID="gdTest" runat="server">
           <Columns>
               <asp:BoundField DataField="From" />
               <asp:BoundField DataField="To" />
               <asp:BoundField DataField="Area" />
               <asp:BoundField DataField="Sector" />
               <asp:BoundField DataField="CompanyName" />



           </Columns>
       </asp:GridView>


这篇关于柱&QUOT;从&QUOT;不属于该表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆