2016-03-28 84 views
0
when I am trying to bind data to GridView in asp.net it shows the error  "DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'o_id'..". can anyone one please help me. 

this is my database table fields: 
     o_id int primary key identity(1,1), 
     o_date nvarchar(20) , 
     o_time nvarchar(20), 

     name_project nvarchar(60), 

.aspx頁面中數據綁定: 'System.Data.DataRowView' 不包含與名稱的屬性 'o_id'

<asp:GridView ID="GvProj" runat="server" AllowPaging="True" CssClass="AllGrid" 
     PagerStyle-CssClass="pgrAll" DataKeyNames="o_id"> 
     <PagerStyle CssClass="pgrAll"></PagerStyle> 
     <RowStyle BackColor="#ffffff" ForeColor="#000000" /> 
    <HeaderStyle BackColor="#4a70d0" ForeColor="#ffffff" /> 
    <AlternatingRowStyle BackColor="#c0c0c0" ForeColor="#000000"FontSize="14px" /> 
    </asp:GridView> 

.cs文件

cmd.CommandText =「選擇o_id作爲ID,o_date作爲DATE,name_project作爲來自OrderManagement的NAME「;

   int count = cmd.ExecuteNonQuery(); 
       DataTable dt = new DataTable(); 



       SqlDataAdapter da = new SqlDataAdapter(cmd); 
       da.Fill(dt); 
       GvProj.DataSource = dt; 
       GvProj.DataBind(); 
       GvProj.Visible = true; 
       GvInvidual.Visible = false; 
+0

你在哪裏綁定你的db列到gridview? – Webruster

+0

我只想從名爲「OrderManagement」的表中選擇數據庫數據,並希望在名爲「GvProj」的gridview中顯示。 – Abdu

+0

但是,當我給DataViewName在GridView屬性中不起作用。否則它的工作 – Abdu

回答

0

您的o_ID DB名字是ID因爲你沒有檢索相同,並試圖改變與別名該列。所以請嘗試像這樣改變:

DataKeyNames="ID" 
+1

非常感謝Mr.Webruster ....... – Abdu

相關問題