[WebMethod]
    public  string   cx(string  x)
    {
        string s=null ;
        string str = "Data Source=localhost;Initial Catalog=英语语法;Persist Security Info=true;User ID=sa;Password=123";       
        SqlConnection con = new SqlConnection(str);
        
            string comStr = "select  内容  from 语法  where 类别='x'";
            con.Open();
          
           
            
    //public Service () {
        
        //如果使用设计的组件,请取消注释以下行 
        //InitializeComponent(); 
    //}*/
            SqlCommand com = new SqlCommand(comStr, con);
            SqlDataReader rd = com.ExecuteReader();
       
        if (rd.HasRows)
        {
            while (rd.Read())
            {                s = rd["内容"].ToString();
            }
            
        }
        rd.Close();
        con.Close();
        return s;    }
    
}

解决方案 »

  1.   

    如果要1行的话,查询的时候为什么不用 top 1
      

  2.   

    你自己不是都写得好好的嘛,按照你这样思路就行啦,也可以用dataset来保存结果
    然后DataRow row=ds.Tables[0].Rows[0];这样第一行就赋给了row变量啦
      

  3.   

     可是返回的结果是 <?xml version="1.0" encoding="utf-8" ?> 
      <string xmlns="http://tempuri.org/">select 内容 from 语法 where 类别='x'</string> 
      

  4.   

    你写的都是对的啊,这么可能返回你的sql语句,好好检查一下是不是哪里调用错了~~~
      

  5.   

     可是返回的结果是 <?xml version="1.0" encoding="utf-8" ?> 
      <string xmlns="http://tempuri.org/">select 内容 from 语法 where 类别='x'</string> 
      

  6.   

    select 内容 from 语法 where 类别='x'   --   类别=x就行吧,不用加引号。
    为什么数据库,表,字段都是中文啊,这样不好吧。觉得还是要规范些,不用中文做字段之类的。
      

  7.   

    返回结果有点不对。应该<?xml version="1.0" encoding="utf-8"?>
    <string xmlns="http://tempuri.org/">string</string>  string 就是你查询出的数据