Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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
WebService ASP.NET C#_C#_Asp.net_Web Services - Fatal编程技术网

WebService ASP.NET C#

WebService ASP.NET C#,c#,asp.net,web-services,C#,Asp.net,Web Services,我在一个WebService中创建了一个WebMethod,它使用存储过程查找您正在搜索的内容 [WebMethod] public DataSet getMyData(string search) { using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True

我在一个WebService中创建了一个WebMethod,它使用存储过程查找您正在搜索的内容

[WebMethod]
public DataSet getMyData(string search)
{
    using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"))
    {
        conn.Open();
        SqlCommand cmd = new SqlCommand("searchingads", conn);
        SqlDataAdapter da;
        DataSet ds = new DataSet();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@search", search);
        da = new SqlDataAdapter(cmd);
        da.Fill(ds, "MyData");

        conn.Close();


        conn.Close();
        return ds;
    }
我不知道如何从ASP.NET应用程序调用此方法。我有一个按钮,单击它时,需要调用此方法并填充GridView

我的ASP.NET web应用程序中有以下代码(单击按钮):

当点击按钮时,标签会切换到“hello world”,但当我搜索时,它不会给我任何表格

提前感谢您的帮助。

请使用此

GridView2.DataSource=service.getMyData(TextBox1.Text)

而不是


GridView2.DataSource=service.IskanjeOglasov(TextBox1.Text)

如果已测试搜索逻辑及其返回的数据,请尝试将数据表指定为数据源而不是数据集

GridView2.DataSource = ((DataSet)service.getMyData(TextBox1.Text)).Tables[0];
GridView2.DataBind();

在这里,我删除了数据集的检查部分。这可能会起作用。

在asp.net应用程序中添加服务引用,并通过命名空间添加或直接使用该服务。您的存储过程是否工作正常并提供数据。不是这样,只是类型错误,它仍然没有显示任何数据。然后请使用数据集中的datatable。
GridView2.DataSource = ((DataSet)service.getMyData(TextBox1.Text)).Tables[0];
GridView2.DataBind();