有一张表shorestPaths ,有一个字段PointsPath,是备注类型,里面内容形如“,1,2,3,4,8,14,” ,我写下面的语句去查询返回结果为null,不知道问题出在哪?在Access里面直接查是有结果的,郁闷
count是一个int型数组。
OleDbCommand command = dbconn.CreateCommand();
for (int j = 0; j < count.Length; j++)
{
count[j] = 0;
string id=(j+1).ToString();
command.CommandText = @"SELECT * FROM shorestPaths WHERE (((shorestPaths.[PointsPath]) like '%,"+id+",%'))";
count[j] = command.ExecuteNonQuery();
}
count是一个int型数组。
OleDbCommand command = dbconn.CreateCommand();
for (int j = 0; j < count.Length; j++)
{
count[j] = 0;
string id=(j+1).ToString();
command.CommandText = @"SELECT * FROM shorestPaths WHERE (((shorestPaths.[PointsPath]) like '%,"+id+",%'))";
count[j] = command.ExecuteNonQuery();
}
{
dbconn = new OleDbConnection(path);
dbconn.Open();
DataSet ds = new DataSet(); //创建DataSet对象
da = new OleDbDataAdapter(@"select * from shorestPaths", dbconn); //引用数据库连接dbconn并依据SQL语句"select * from kaizhi"创建OleDbDataAdapter对象da
//da = new OleDbDataAdapter("SELECT * FROM shorestPaths WHERE (((shorestPaths.[PointsPath]) like '%,1,%'))", dbconn);这个查询是有结果的啊
da.Fill(ds, "shorestPaths");
DataSet ds2 = new DataSet();
da = new OleDbDataAdapter(@"select * from Points", dbconn); da.Fill(ds2, "Points");
OleDbCommandBuilder cb = new OleDbCommandBuilder(da); // 创建OleDbCommandBuilder对象cb用于更新OleDbDataAdapter对象da的Insert、Delete、Update指令
da.UpdateCommand = cb.GetUpdateCommand(); //更新OleDbDataAdapter对象da的指令
int[] count = new int[ds2.Tables["Points"].Rows.Count];
OleDbCommand command = dbconn.CreateCommand();
for (int j = 0; j < count.Length; j++)
{
count[j] = 0;
string id=(j+1).ToString();
command.CommandText = @"SELECT * FROM shorestPaths WHERE (((shorestPaths.[PointsPath]) like '%,"+id+",%'))";
count[j] = command.ExecuteNonQuery();
}
for (int j = 0; j < ds2.Tables["Points"].Rows.Count; j++)
{
ds2.Tables["Points"].Rows[j]["pointBetweenness"] = count[j];
}
da.Update(ds2, "Points");
dbconn.Close();
}
这个是Button事件里面的代码,真心不知道物体出在哪儿呀
command.CommandText = "SELECT * FROM shorestPaths WHERE PointsPath like '?,"+id+"?,'";
command.CommandText = "SELECT * FROM shorestPaths WHERE PointsPath like '?,"+id+",?'";问题在于同一条SQL语句,这样使用是有结果的呀
da = new OleDbDataAdapter("SELECT * FROM shorestPaths WHERE (((shorestPaths.[PointsPath]) like '%,1,%'))", dbconn);这个查询是有结果的啊
count[j] = command.ExecuteNonQuery();
直接在Access里面查是返回2025条记录的...忘了说,表里面有200万行记录
这句的意思你明白吗?例如:like '%,1,%' 的
满足条件 是: 0,1,2
而 ,1,2 着是不满足条件的因为 '%, 表是 ,前面要有值.所以你j=0是根本就 没有符合条件的结果.你的查询 条件 第1个和最后一个 数字都是不符合你的查询条件的.由于不知道你的需求 和具体 内容,不好帮你分析什么是对的
我特意查了的,access里面%匹配0个或多个字符;而且查‘,2,’也没有返回结果啊,莫名其妙啊
谢谢你的关注!