Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net es..我只想以我在问题中提到的形式检索这些值以及一个分隔符。有什么办法吗?你想从你的单列中获取所有名称吗?@kleinohad:是的,我有一个单列“name”,其中包含我已经插入的值。我现在只需要以我在帖子中提到的方式使用我的web服务的方法来检索它们,_.net_Web Services_Visual Studio 2008 - Fatal编程技术网

.net es..我只想以我在问题中提到的形式检索这些值以及一个分隔符。有什么办法吗?你想从你的单列中获取所有名称吗?@kleinohad:是的,我有一个单列“name”,其中包含我已经插入的值。我现在只需要以我在帖子中提到的方式使用我的web服务的方法来检索它们,

.net es..我只想以我在问题中提到的形式检索这些值以及一个分隔符。有什么办法吗?你想从你的单列中获取所有名称吗?@kleinohad:是的,我有一个单列“name”,其中包含我已经插入的值。我现在只需要以我在帖子中提到的方式使用我的web服务的方法来检索它们,,.net,web-services,visual-studio-2008,.net,Web Services,Visual Studio 2008,es..我只想以我在问题中提到的形式检索这些值以及一个分隔符。有什么办法吗?你想从你的单列中获取所有名称吗?@kleinohad:是的,我有一个单列“name”,其中包含我已经插入的值。我现在只需要以我在帖子中提到的方式使用我的web服务的方法来检索它们,是否有充分的理由用“#”而不是标准的逗号来分隔?(因为你不用进行字符串连接,只需依靠web服务为你序列化数组即可)@Emo:非常感谢你的编辑和代码。我试过了。但当我点击浏览器中的调用按钮时,我得到了这个结果[@Emo:Yes,你最近编辑的代码运



es..我只想以我在问题中提到的形式检索这些值以及一个分隔符。有什么办法吗?你想从你的单列中获取所有名称吗?@kleinohad:是的,我有一个单列“name”,其中包含我已经插入的值。我现在只需要以我在帖子中提到的方式使用我的web服务的方法来检索它们,是否有充分的理由用“#”而不是标准的逗号来分隔?(因为你不用进行字符串连接,只需依靠web服务为你序列化数组即可)@Emo:非常感谢你的编辑和代码。我试过了。但当我点击浏览器中的调用按钮时,我得到了这个结果[@Emo:Yes,你最近编辑的代码运行良好..但我只想在它从我的数据库中获取每条记录后插入一个分隔符..例如:john#ann#joe@Parth_90:我添加了分隔符。如果您需要很多名称,最好在添加名称时切换回字符串数组或字符串生成器。嘿,谢谢!!实际上我不知道有很多名称要获取..因此将仅使用此名称。感谢所有帮助!!:-)@Parth_90:没问题,很乐意提供帮助。一点建议:切换回(如果可能)返回字符串数组。这更简单,更不容易出错(如果名称包含
)@Emo:非常感谢您的编辑和代码。我试过了。但是当我点击浏览器中的调用按钮时,我得到了这个消息[@Emo:Yes,你最近编辑的代码运行良好..但我只想在它从我的数据库中获取每条记录后插入一个分隔符..例如:john#ann#joe@Parth_90:我添加了分隔符。如果您需要很多名称,最好在添加名称时切换回字符串数组或字符串生成器。嘿,谢谢!!实际上我不知道有很多名称要获取..因此将仅使用此名称。感谢所有帮助!!:-)@Parth_90:没问题,很乐意提供帮助。一点建议:切换回(如果可能)返回字符串数组。这更简单,更不容易出错(如果名称包含
)是的,我遵循你的方法,是的,这是一种比我更好的方法。因为我是C#新手,特别是,我会花一些时间。但只要像你这样的人帮助我更好地理解事物,我觉得我会学得更快:-)是的,我遵循你的方法,是的,这是一种比我更好的方法。因为我是C#新手,尤其是我这需要一些时间。但只要像你这样的人能帮助我更好地理解事物,我觉得我会学得更快:-)
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace WebService10
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment
 the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {
        String[] result=new String[40];
        String[] result2 = new String[40];

        [WebMethod]
        public String[] getData()
        {
            SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123");
            try
            {
                myConnection.Open();

                SqlCommand myCommand = new SqlCommand();
                myCommand.Connection = myConnection;
                myCommand.CommandText = "select count(*) from names where name =@name";

                SqlDataReader myReader = myCommand.ExecuteReader();

                //while
                for(int i=0;i<40;i++)
                {
                    if (myReader.Read())
                    {
                         result[i]= myReader["name"].ToString();
                         result2[i] = result[i] + "#";
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                myConnection.Close();
            }

            return result2;
        }
    }
}
public class Service1 : System.Web.Services.WebService
{

    [WebMethod]
    public String getData(string nameFilter)
    {
        String result = "";

        SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123");
        try
        {
            myConnection.Open();

            SqlCommand myCommand = new SqlCommand();
            myCommand.Connection = myConnection;
            myCommand.CommandText = "select name from names where name =@name";
            myCommand.Parameters.AddWithValue("@name", nameFilter);
            SqlDataReader myReader = myCommand.ExecuteReader();

            while(myReader.Read())
            {
                if(result.Length > 0)
                {
                    result += "#";
                }
                result += myReader["name"].ToString();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            myConnection.Close();
        }

        return result;
    }
}
public class Service1 : System.Web.Services.WebService
{

    [WebMethod]
    public String[] getData(string nameFilter)
    {
        var names = new List<string>();
        SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123");
        try
        {
            myConnection.Open();

            SqlCommand myCommand = new SqlCommand();
            myCommand.Connection = myConnection;
            myCommand.CommandText = "select name from names where name = @name";
            myCommand.Parameters.AddWithValue("@name", nameFilter);
            SqlDataReader myReader = myCommand.ExecuteReader();

            while(myReader.Read())
            {
                names.Add(myReader["name"].ToString());
            }
        }
        catch (Exception ex)
        {
            //Console.WriteLine(ex.Message);
        }
        finally
        {
            myConnection.Close();
        }

        return names.ToArray();
    }
}
 [WebMethod]
    public string getData()//changed to return string
    {

        SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123");
        try
        {
            myConnection.Open();

            SqlCommand myCommand = new SqlCommand();
            myCommand.Connection = myConnection;
            myCommand.CommandText = "select name from names";//you can make it select distinct

            SqlDataReader myReader = myCommand.ExecuteReader();
            string toReturn = "";
            while(myReader.Read())
            {
                if (myReader.Read())
                {
                     toReturn += myReader["name"].ToString() + "#";
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            myConnection.Close();
        }

        return toReturn; //# as delimiter
    }
select name from names
var result = new List<string>();
while(myReader.Read())
{
  result.Add(reader["name"].ToString() + "#");
}

return result.ToArray();
return string.Join("#", result.ToArray())