0

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

1 回答 1

0

您不能直接在 C# 中调用函数。像这样试试

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

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

于 2012-08-09T14:15:57.653 回答