列を自分datatable
に追加し、条件に基づいて列に値を追加しましたが、値が追加されませんdatatable
(値があるはずですが)
これは私が使用したコードの一部です
conn = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;
Data Source =" + Server.MapPath("App_Data\\LR Product Database 2000.mdb"));
conn.Open();
Dictionary<string, string> items = new Dictionary<string, string>();
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT CODE, TITLE FROM tblProducts";
OleDbDataReader dbread = cmd.ExecuteReader();
while (dbread.Read())
{
productCode = (string)dbread["CODE"];
productTitle = (string)dbread["TITLE"];
System.Diagnostics.Debug.Write(productCode + " ");
items.Add(productCode, productTitle);
}
sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["LRVWebsite"].ToString());
sqlCon.Open();
dsSql = new DataSet();
SqlDataAdapter dba = new SqlDataAdapter(@"SELECT C.CustomerFirstName,C.CustomerLastName, C.CustomerCompany,C.CustomerPosition,C.CustomerCountry,C.CustomerProvince,C.CustomerContact,CP.ActionDate,CP.ProductCode,CP.CustomerEmail FROM tblCustomers C INNER JOIN tblCustomerProducts CP ON C.CustomerEmail = CP.CustomerEmail ORDER BY ActionDate DESC", connString);
dba.Fill(dsSql,"Products");
DataTable dt = dsSql.Tables["Products"];
dt.Columns.Add("Title", typeof(string));
foreach (DataRow dr in dt.Rows)
{
if(items.ContainsKey(dr["ProductCode"].ToString()))
{
dr["Title"] = items[dr["ProductCode"].ToString()];
}
}
条件に基づいて新しい列に値を追加するにはどうすればよいですか。