日期:2014-05-18  浏览次数:20830 次

两个SQL字符串一样。。。sql 能得到DataReader集。。。sql2 取不出集。。。
两个SQL字符串一样。。。
sql 能得到DataReader集
sql2 取不出集。。。

public GetDFDFD(DataTable dt){
  string[] BB = new string[] { "'d41d8cd98f00b204e9800998ecf8427e '", "'" + dt.Rows[1]["Description"].ToString() + " '" };

  string value = "";
  string strconn = "user id=sa;password=sa;";
  strconn += "initial catalog=vba;Server=BB-SX6PP2ZULG;";
  strconn += "Connect Timeout=30";
  string sql = "",sql2="";
   
  sql = "SELECT [path_portfolio] FROM [vba].[dbo].[vba_path_title] where [path_md5]=" + BB[0];
  sql2 = "SELECT [path_portfolio] FROM [vba].[dbo].[vba_path_title] where [path_md5]=" + BB[1];
  SqlCommand command = new SqlCommand();
  SqlConnection conn = new SqlConnection(strconn);
  conn.Open();
  command.Connection = conn;
  command.CommandText = sql;
  SqlDataReader dr = command.ExecuteReader();
  dr.Read();
  if ((bool)dr.HasRows)
  {
  dr.Read();
  value = dr["path_portfolio"].ToString() + sql + sql2;
  }
  dr.Close();
  command.Dispose();
  conn.Close();
}
输出
sql=SELECT [path_A] FROM [DB].[dbo].[A] where [path]='d41d8cd98f00b204e9800998ecf8427e '
sql2=SELECT [path_A] FROM [DB].[dbo].[A] where [path]='d41d8cd98f00b204e9800998ecf8427e '

------解决方案--------------------
看你代码好像都没有对sql2进行
conn.Open(); 
command.Connection = conn; 
command.CommandText = sql; 
SqlDataReader dr = command.ExecuteReader(); 
dr.Read(); 
if ((bool)dr.HasRows) {...}

吧!!!

------解决方案--------------------
两个SQL语句都在查询分析器里跑下看看,可能有空格的问题,空格是必须的吗?
sql =SELECT [path_A] FROM [DB].[dbo].[A] where [path]='d41d8cd98f00b204e9800998ecf8427e ' 
sql2=SELECT [path_A] FROM [DB].[dbo].[A] where [path]='d41d8cd98f00b204e9800998ecf8427e ' 
或改成这样试下
C# code
sql2 = string.Format("SELECT [path_A] FROM [vba].[dbo].[A] where [path_md5]='{0} '",dt.Rows[1]["Description"].ToString());