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.
希望这对你有帮助,谢谢。