Created
July 28, 2021 12:11
-
-
Save ayubmetah/da00cffa145fb1ef8b7ab06df62cb18b to your computer and use it in GitHub Desktop.
C# class to insert record into SQL database
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
admusing System; | |
using System.Data; | |
using System.Data.SqlClient; | |
namespace DataServices | |
{ | |
public class DataService : IDataService | |
{ | |
public string InsertData(string Name, String Email, string Message) | |
{ | |
SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog="DataBase Name";User ID="User Name";Password="Password""); | |
SqlCommand cmd = new SqlCommand("SP_InsertProc", con); | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.Parameters.AddWithValue("@name", Name); | |
cmd.Parameters.AddWithValue("@email", Email); | |
cmd.Parameters.AddWithValue("@message", Message); | |
con.Open(); | |
cmd.ExecuteNonQuery(); | |
con.Close(); | |
return "Success"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment