Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.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
C# 搜索时将sql过程与Visual studio连接时出错_C#_Sql Server_Search - Fatal编程技术网

C# 搜索时将sql过程与Visual studio连接时出错

C# 搜索时将sql过程与Visual studio连接时出错,c#,sql-server,search,C#,Sql Server,Search,我只是想做搜索栏,我已经用webservice做了,但现在我只停留在一个地方。我犯了一个错误 过程或函数“getTable”需要参数“@term”,该参数为 没有供应 cs代码为: public void getB2bData(string term) { string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlCo

我只是想做搜索栏,我已经用webservice做了,但现在我只停留在一个地方。我犯了一个错误

过程或函数“getTable”需要参数“@term”,该参数为 没有供应

cs代码为:

public void getB2bData(string term)
{
    string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
    using (SqlConnection con = new SqlConnection(cs))
    {
        //Search
        using (SqlCommand cmdSearch = new SqlCommand("dbo.getTable", con))
        {
            cmdSearch.CommandType = CommandType.StoredProcedure;

            if (string.IsNullOrEmpty(term))
            {
                cmdSearch.Parameters.Add(new SqlParameter("@search",term));
            }
            con.Open();
            SqlDataReader rdr = cmdSearch.ExecuteReader();
            gvSearchNames.DataSource = rdr;
            gvSearchNames.DataBind();
        }
    }
}

protected void btnSubmit_Click(object sender, EventArgs e)
{        
    getB2bData(txtName.Text); 
}

getTable
需要
@term
,然后传递
@search
参数

更改:

cmdSearch.Parameters.Add(new SqlParameter("@search", term));
致:


什么是dbo.getTable?该错误表示您使用的是sp或函数,它需要您未提供的参数。在您提供此参数之前,它不会起作用。您可能希望向海报提供一些建议,说明在
术语
null
或为空时该怎么办(因为该代码在该场景中可能不起作用)。
cmdSearch.Parameters.Add(new SqlParameter("@term", term));