使用xml在wcf中的值不能为null

时间:2015-07-14 15:59:31

标签: c# string wcf xmlreader stringreader

我将triong converto string转换为xml但是当代码运行时#34;值不能为null"怎么能解决这个问题?项目在Windows Phone 8中运行

public string baslıkbul(baslıkı ba)
    {
        SqlConnection bag = new SqlConnection(ConfigurationManager.ConnectionStrings["baglantı"].ConnectionString.ToString());
        bag.Open();
        SqlCommand yap = new SqlCommand("select Baslık from AN where AD=@ad",bag);
        yap.Parameters.AddWithValue("@ad", ba.AD);
        yap.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter(yap);
        DataSet ds = new DataSet();
        da.Fill(ds);
        string s = ds.GetXml(); /// this line is running

        XmlReader okuyucu = XmlReader.Create(new StringReader(s));
        while(okuyucu.Read())
        {
            if(okuyucu.NodeType==XmlNodeType.Element)
            {
                switch(okuyucu.Name)
                {
                    case"Baslık":
                        s = Convert.ToString(okuyucu.ReadString());

                        s = ba.Baslık;
                        break;
                }
            }
        }


        bag.Close();
        return ba.Baslık;

1 个答案:

答案 0 :(得分:0)

您提供给ad参数(即。ba.AD)的价值最有可能是null。如果您要在WHERE子句中使用的值进行过滤,则应该传递System.DBNull