我试着在asp.net代码中使用标量函数并想使用taht,但是我有一个错误,那就是“在f1附近的语法不正确”“函数名”f

时间:2022-02-01 23:09:42

sql code

sql代码

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

C# code

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();
    }
}

1 个解决方案

#1


0  

You Can't call a function directly in C#. Try like this,

不能直接在c#中调用函数。这样的尝试,

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

Hope this helps you, Thank you.

希望这对你有帮助,谢谢。

#1


0  

You Can't call a function directly in C#. Try like this,

不能直接在c#中调用函数。这样的尝试,

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

Hope this helps you, Thank you.

希望这对你有帮助,谢谢。