Created
December 31, 2013 07:56
-
-
Save swkwon/8193846 to your computer and use it in GitHub Desktop.
SQL Server custom function, custom stored procedure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Data.SqlClient; | |
using System.Data.SqlTypes; | |
using Microsoft.SqlServer.Server; | |
namespace SqlServerProject5 | |
{ | |
public class Class1 | |
{ | |
[SqlFunction] | |
public static SqlInt32 GetSquare(SqlInt32 param) | |
{ | |
return param * param; | |
} | |
[SqlProcedure] | |
public static void InsertUser(SqlString name, SqlInt32 score) | |
{ | |
string insertQuery = "INSERT INTO myUser(user_name, user_score) VALUES(@name, @score)"; | |
using (SqlConnection conn = new SqlConnection(@"context connection=true")) | |
{ | |
conn.Open(); | |
using (SqlCommand cmd = new SqlCommand(insertQuery, conn)) | |
{ | |
cmd.Parameters.Add("@name", System.Data.SqlDbType.VarChar, 50); | |
cmd.Parameters.Add("@score", System.Data.SqlDbType.Int); | |
cmd.Parameters[0].Value = name; | |
cmd.Parameters[1].Value = score; | |
cmd.ExecuteNonQuery(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment