Wince SQLce 数据库连接的怪事

e_zhiwen e_zhiwen 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
先看代码:


DB d = new DB();

//string sql = "Select BarcodeType,BarcodeContext From BarcodeTable Where Barcode='"+textBox1.Text.Trim()+"'";
string sql="Select Barcode,Barcodetype,barcodecontext from barcodetable where barcode like '%"+textBox1.Text.Trim()+"%'";
// string sql = "Select Barcode,Barcodetype,barcodecontext from barcodetable";
DataTable dt1 = new DataTable();
dt1 = d.SelectContext(sql);
dataGrid1.DataSource = dt1;

带条件的无法取到数据,不带条件的可以取到数据.有点不太清楚为什么?

//再次修改过了条件,用模拟的又可以出结果。为什么呢?


public DataTable SelectContext(string sql)
{
SqlCeConnection conn=opensqlce();
DataTable dt = new DataTable();
DataSet ds = new DataSet();
try
{

SqlCeCommand cmd = new SqlCeCommand(sql, conn);
SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);

da.Fill(ds);
dt = ds.Tables[0];

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return dt;



}
private SqlCeConnection opensqlce()
{
string ceConnStr = @"Data Source ="+System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)+"\\TPM.sdf";
SqlCeEngine engine = new SqlCeEngine(ceConnStr);
SqlCeConnection connMobile = new SqlCeConnection(ceConnStr);
try
{
connMobile.Open();
}
catch (Exception ex)
{
MessageBox.Show("不能连接数据库!" + ex.Message);
return null;
}
return connMobile;
}


此数据完全无错,可是当代入我在数据库验证过的SQL有1 条记录,在断点调试中就是取不到结果。请教下高手帮忙!
...全文
评论 4
收藏 已收藏
分享
返回顶部
e_zhiwen
C# 111,129 成员 642,539 内容