ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 278.1k

Error out parameter must be assigned before control leave cu

Aug 14 2019 2:14 PM
Problem
Error out parameter must be assigned before control leave current method .
function GetInsertStatmentText below return full insert statement as below
  1. INSERT INTO master_table(id, branch_id, name, address, phone) VALUES(@id, @branch_id, @name, @address, @phone);  

in out paramter i need to return
  1. @id, @branch_id, @name, @address, @phone  

when i add out parameter to function i get error :
 
Error out parameter must be assigned before control leave current method
 
How to solve this error please ?

What I have tried:
  1. public static string GetInsertStatmentText(string JsonData,out  sqp)  
  2.         {  
  3.             string Insert = "";  
  4.             JObject jo = JObject.Parse(JsonData);  
  5.             JToken m = jo["master"];  
  6.             string connectionstring = "Server=AHMEDSALAH-PC\\SQL2014;Database=Atum;User Id=sa;Password=abc123;"//change connection string  
  7.             using (SqlConnection connection = new SqlConnection(connectionstring))  
  8.             {  
  9.                 using (SqlCommand command = new SqlCommand(JsonHelper.GetInsertStatement(m), connection))  
  10.                 {  
  11.                     connection.Open();  
  12.                     List<SqlParameter> lsp = JsonHelper.GetSqlParams(jo["master"]);  
  13.                     foreach (SqlParameter sqp in lsp)  
  14.                         command.Parameters.Add(sqp);  
  15.                     Insert = command.CommandText;  
  16.                 }  
  17.             }  
  18.             return Insert;  
  19.   
  20.         }  
 

Answers (3)