최상의 솔루션을 원합니다.Datatable 또는 Datable A와 테이블을 비교하고 Datatable B와 함께 테이블을 업데이트하는 방법 #
Dt_AllPage
(2 열 및 meny 행 포함) column 0 = ModelRam and Column 1 = Price.
문자열. 열 [dbo].[TBL_Sku_RAM]
: [ID]int,[SKU]string,[ModelRam]string,[Price]string
내가 TBL_Sku_RAM
의 각 행 'colmun SKU로 Dt_AllPage
의 각 rows'column의 ModelRam을 비교하려는
. 이것에 대한
, tbl_sku_ram
에서 선택하고 Dt_SelectTBlRAM
에 추가하고 이름을 가진 두 개의 DataTable을 비교 : Dt_AllPage
Dt_SelectTBlRAM
과를 다음 Dt_SelectTBlRAM
에 Dt_AllPage
의 정규식 하나 개의 행을 존재하는 경우, Dt_SelectTBlRAM
의 ID
를 얻을이 rowexist의 가격을받을 Dt_AllPage
및 업데이트 열 : [ModelRam], [Price] of [dbo].[TBL_Sku_RAM]
;
예 :
012에서 :
Dt_AllPage
ModelRam Price
-------------- ----------
4GB DDR3 PC3 1,000
8GB DDR3 PC3L Geil 1.35V 5,000
ID Sku ModelRam Price
--- ----------------- -------------- ----------
1 8GBDDR3 pc3L-1600 null null
2 1GBDDR3-1066 null null
3 2GBDDR2-800 null null
4 1GBDDR2-667 null null
[dbo].[TBL_Sku_RAM]
에서 출력
ID Sku ModelRam Price
--- ----------------- -------------- ----------
1 8GBDDR3 pc3L-1600 8GB DDR3 PC3L Geil 1.35V 5,000
2 1GBDDR3-1066 null null
3 2GBDDR2-800 null null
4 1GBDDR2-667 null null
번호 :
1)
for (int i = 0; i < Dt_AllPage.Rows.Count; i++)
{
Model_name = Dt_AllPage.Rows[i][0].ToString();
DataSet Ds_SelectTBlRAM = DAL.SelectTBlRAM();
DataTable Dt_SelectTBlRAM = Ds_SelectTBlRAM.Tables[0];
for (int RowTBL = 0; RowTBL < Dt_SelectTBlRAM.Rows.Count; RowTBL++)
{
if (Regex.IsMatch(Dt_SelectTBlRAM.Rows[RowTBL][1].ToString(), Model_name))
{
int ModelId = (int)Dt_SelectTBlRAM.Rows[RowTBL][0];
string Price = Dt_AllPage.Rows[i][1].ToString();
DAL.Update_Price_Model(Model_name, Price, ModelId);
}
}
}
2)
for (int i = 0; i < .Rows.Count; i++)
{
Model_name = Dt_AllPage.Rows[i][0].ToString();
DataSet Ds_SelectTBlRAM = DAL.SelectTBlRAM();
DataTable Dt_SelectTBlRAM = Ds_SelectTBlRAM.Tables[0];
DataRow row1 = Dt_SelectTBlRAM.AsEnumerable().FirstOrDefault(r => r.Field<string>("SKU").Contains(Model_name));
foreach (DataRow row2 in Dt_SelectTBlRAM.Rows)
{
if (row1 != null)
{
int Model_ID = (from DataRow DR in Dt_SelectTBlRAM.Rows
where (string)DR["SKU"] == Model_name
select (int)DR["ID"]).FirstOrDefault();
}
}
string Price = Dt_AllPage.Rows[i][1].ToString();
Model_name = Dt_AllPage.Rows[i][0].ToString();
}
명확하지 않다면 u에 대한 코멘트를 요청하고 닫지 않으십시오. – RedArmy
'Dt_SelectTBlRAM'에 대한 구성표를 추가하고 현재 코드에서 작동하지 않는 것을 알려주십시오. –
구성표 란 무엇입니까? 데이터 테이블에 대한 체계를 추가하는 방법을 모르겠다. (( – RedArmy