我在这个列表中有名称temp1的类型字符串列表我有一组单词,每个单词我计算N00,N01,N10,N11,MI最后它正在抛出异常更新无法找到TableMapping [ 'sample']或DataTable'sample'。 .plz help
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 ['sample']或DataTable'sample'。
答案 0 :(得分:1)
我猜您在代码中缺少表格映射。
取自MSDN:“如果在调用DataAdapter的Fill或Update方法时未指定TableName或DataTableMapping名称,DataAdapter将查找名为”Table“的DataTableMapping。如果DataTableMapping不存在,则DataTable的TableName将为“Table”。您可以通过创建名为“Table”的DataTableMapping来指定默认的DataTableMapping。“
http://msdn.microsoft.com/en-us/library/ks92fwwh(vs.71).aspx