2014-09-04 46 views
0

我在填充我的DevExpress Gridview時遇到了一些問題,我想要一個兩級的gridview並使用SqlCommand。起初,我創建了一個Dataset並添加了兩個表格,併爲它們定義了關係。但它不起作用。你能幫我找到我的問題嗎?使用DataAdapter和SqlCommand填充Devexpress GridView代碼

這裏是我的代碼

string owner = "SELECT [OBJECTID],[Name] ,[Family] ,[Father] ,[Dftarche] ,[Birthday] ,[education] ,[home_address] ,[farm_address] ,[ensurance] ,[phone] ,[home_number] ,[owner_id] FROM [dbo].[OWNER]"; 
string property = "SELECT [number] ,[owner_ID] ,[GPSId] ,[Energy],[corp_type] ,[Pool],[irrigation] ,[variety] ,[trees] ,[utilizat] ,[address] ,[water_hour] ,[w_source] ,[w_inche],[w_dore],[NoeMalekiat],[MotevasetBardasht],[Area] ,[OBJECTID],[Shape] FROM [dbo].[Property] "; 

string strConnString = Properties.Settings.Default.land_gisConnectionString; 

SqlConnection con = new SqlConnection(strConnString); 
con.Open(); 
SqlCommand command = new SqlCommand(owner, con); 
       SqlDataAdapter adapter = new SqlDataAdapter(); 
       System.Data.DataSet dsMain = new System.Data.DataSet(); 
       adapter.SelectCommand = command; 
       adapter.Fill(dsMain, "First Table"); 

       adapter.SelectCommand.CommandText = property; 
       adapter.Fill(dsMain, "Second Table"); 


       dsMain.Tables.Add(iFeatureSet.DataTable.Copy()); 
       adapter.Dispose(); 
       command.Dispose(); 
       DataRelation newRelation = new DataRelation("املاک شخصی", dsMain.Tables["First Table"].Columns["owner_id"], dsMain.Tables["Second Table"].Columns["owner_ID"]); 
       dsMain.Relations.Add(newRelation); 
       GridAttrebuteTable.DataSource = dsMain.Tables[2]; 
      // gridView5.DataSource = dsMain.Tables[1]; 
       dataGridView1.DataSource = dsMain; 

我搜索,發現這個http://msdn.microsoft.com/en-us/library/bh8kx08z.aspx,看來我的代碼是正確的,但它並不顯示網格任何

非常感謝您的幫助

我可以弄清楚如何解決它。它現在工作正常(上面的代碼被編輯),但現在如果我添加一個新的DataTable我不知道爲什麼它不能再次工作

回答

1

對於每個細節表,您需要新的GridView。您不能在相同的GridView中同時顯示主控和詳細信息。

Try this example

+0

非常感謝 – 2014-09-04 18:44:25