Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.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
我试图使用标量函数,并希望在asp.net代码中使用taht,但我发现错误是“f1附近的语法不正确”“函数名”f_Asp.net_Sql - Fatal编程技术网

我试图使用标量函数,并希望在asp.net代码中使用taht,但我发现错误是“f1附近的语法不正确”“函数名”f

我试图使用标量函数,并希望在asp.net代码中使用taht,但我发现错误是“f1附近的语法不正确”“函数名”f,asp.net,sql,Asp.net,Sql,sql代码 create function f1( @pay float) returns float as begin return(@pay*8*10) end C代码 protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["abc"]);

sql代码

create function f1( @pay float)
returns float
as
begin
return(@pay*8*10)
end
C代码

protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["abc"]);


        float a;
        SqlCommand cmd = new SqlCommand("dbo.f1",con);
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@pay",TextBox1.Text);
        //cmd.Parameters.AddWithValue("@uname", TextBox2.Text);

        con.Open();
        a = (float)(cmd.ExecuteScalar());
        TextBox2.Text = System.Convert.ToString(a);
        con.Close();
    }
}

不能在C中直接调用函数。 试着这样,

cmd.CommandText = "SELECT COUNT(*) FROM dbo.f1";
Int32 count = (Int32) cmd.ExecuteScalar();

希望这对您有所帮助,谢谢。

类似于此,您可以使用Select dbo.f1SuganR Plz解释我在示例cmd.Parameters中从textbox1.text获取的值。AddWithValue@pay,TextBox1.Text;将到达函数f1作为参数。由于函数f1需要SQL中的参数..@Rahul,因此需要创建一个过程并在那里调用函数。在C语言中,调用过程并传递参数。希望这对你有帮助。非常感谢。