1
我有列表中的名稱爲temp1的字符串在此列表中我有一組單詞爲每個單詞即時計算N00,N01,N10,N11,MI最後它是拋出異常更新無法找到TableMapping ['sample']或DataTable'sample'。 .plz幫助c#錯誤與數據集更新
DataSet dsSelectAll = new DataSet();
SqlCommand cmdSelectAll = new SqlCommand("select * from sample", con);
SqlDataAdapter daSelectAll = new SqlDataAdapter(cmdSelectAll);
SqlCommandBuilder scb = new SqlCommandBuilder(daSelectAll);
daSelectAll.FillSchema(dsSelectAll,SchemaType.Mapped, "sample");
foreach (string ri in temp1)
{
//for (int a3 = 0; a3 < ssl.Count; a3++)
{
cmdT.CommandText = @"SELECT * FROM [vijay].[dbo].[sample] where keyword in ('y','" + ri + "')";
// ds.Tables.Clear();
da.Fill(ds);
// row 1 :: 1 0 0 1 0 0
// row 2:: 2 7 0 0 0 1
int N00 = 0;
int N01 = 0;
int N10 = 0;
int N11 = 0;
for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
{
// N00
if (ds.Tables[0].Rows[0][i].ToString() == "0")
{
if (ds.Tables[0].Rows[1][i].ToString() == "0")
{
N00++;
}
}
// N01
if (ds.Tables[0].Rows[0][i].ToString() == "1")
{
if (ds.Tables[0].Rows[1][i].ToString() == "0")
{
N01++;
}
}
// N10
if (ds.Tables[0].Rows[0][i].ToString() == "0")
{
if ((ds.Tables[0].Rows[1][i].ToString()) !="0")
{
N10++;
}
}
// N11
if (ds.Tables[0].Rows[0][i].ToString() == "1")
{
if (ds.Tables[0].Rows[1][i].ToString()!="0")
{
N11++;
}
}
}
//if (a3 == (ssl.Count - 1))
{
//SqlCommand ins = new SqlCommand("update sample set N00=" + N00 + " where KeyWord='" + ri + "'", con);
//ins.ExecuteNonQuery();
DataRow[] drSelectAll = ds.Tables[0].Select("KeyWord='" + ri + "'");
drSelectAll[0]["N00"] = N00;
drSelectAll[0]["N01"] = N01;
drSelectAll[0]["N10"] = N10;
drSelectAll[0]["N11"] = N11;
double n = N00 + N11 + N10 + N01;
double w1 = Convert.ToDouble((N11/n) * (Math.Log(((n * N11)/((N10 + N11) * (N01 + N11))), 2)));
double w2 = Convert.ToDouble((N01/n) * (Math.Log(((n * N01)/(((N01 + N00) * (N01 + N11)))), 2)));
double w4 = Convert.ToDouble((N00/n) * (Math.Log(((n * N00)/(((N00 + N01) * (N00 + N10)))), 2)));
double w3 = Convert.ToDouble((N10/n) * (Math.Log(((n * N10)/(((N10 + N11) * (N00 + N10)))), 2)));
if (w1.ToString() == "NaN")
{
w1 = 0;
}
if (w2.ToString() == "NaN")
{
w2 = 0;
}
if (w3.ToString() == "NaN")
{
w3 = 0;
}
if (w4.ToString() == "NaN")
{
w4 = 0;
}
double ni = w1 + w2 + w3 + w4;
drSelectAll[0]["MI"] = ni;
ds.Tables[0].Rows.Add(drSelectAll);
}
}
}
try
{
daSelectAll.Update(ds, "sample");
}
catch (Exception)
{
throw;//error
}
錯誤:更新找不到TableMapping [ '樣品']或DataTable的 '樣本'。