SQL Store Procedure Call Function In .NET Core Console Application

Introduction

 
In this function, the SQL procedure table reads a procedure call method in the .NET Core application for the basic console write to get the input value to the search result. The SQL procedure calls to select the statement from the database.
 
 Create Table 
  1. CREATE TABLE wincurd (      
  2. Username nchar(10),      
  3. Passwords nchar(10)  
  4. );  
 SQL Procedure
  1. CREATE PROCEDURE  procselect  @username nchar(10)    
  2. AS    
  3.      select * from wincurd where username=@username     
  4. go      
Basic string console values get functionality:
  1. string val;  
  2. Console.Write("Enter value: ");  
  3. val = Console.ReadLine();  
  4. string a = Convert.ToString(val);  
  5. Console.WriteLine("Your input: {0}", a);  
SQL Connection string functionality:
  1. SqlConnection dc = new SqlConnection("Data Source=.;Initial Catalog=databasename;Integrated Security=True");   
Command Execution Functionality
  1. using(SqlCommand cmd = new SqlCommand("procselect", dc)) {  
  2.     cmd.CommandType = CommandType.StoredProcedure;  
  3.     cmd.Parameters.AddWithValue("@username", a.ToString());  
  4.     dc.Open();  
  5.     SqlDataReader dr;  
  6.     dr = cmd.ExecuteReader();  
  7.     if (!dr.Read()) {  
  8.         Console.Write("Record not found ");  
  9.     } else {  
  10.         string b = Convert.ToString(val);  
  11.         b = dr[1].ToString();  
  12.         Console.WriteLine("Your PASSWORD: {0}", b.ToString());  
  13.         Console.ReadLine();  
  14.     }  
  15.     dc.Close();  
  16. }  
Sample Output:
 
 

Conclusion

 
The function console writes to read the value process to SQL connection string executed in the command type functionality and the parameter parses the value of string SQL connection that's open to execute the SQL reader. If data is not available, the console white line message shows. Otherwise, it reads your connection array of values.