I have a stored procedure that its been called by a console application in C#. The stored procedure has some required parameters to be executed. What I am trying to achieve its to be able to enter one of the required parameters into the console once the console is executed.
Something like having a text into the console asking to enter the project name and then hit on enter.
Here's my code:
try
{
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Test"].ConnectionString))
{
string outCsvFile = @"D:\\test\\test.csv";
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Connection = conn;
sqlCmd.CommandText = "projects";
//Adding values to the stored procedure
sqlCmd.Parameters.AddWithValue("@ProjectTitle", "Test Project 1"); //this value I would like to add it when the console application is executed when I will hit on enter.
sqlCmd.Parameters.AddWithValue("@Category", "");
conn.Open();
SqlDataReader reader = sqlCmd.ExecuteReader();
using (System.IO.StreamWriter file = new System.IO.StreamWriter(outCsvFile))
{
file.WriteLine(reader.GetName(0) + ',' + reader.GetName(1));
while (reader.Read())
file.WriteLine(reader[0].ToString() + ',' + reader[1].ToString());
}
conn.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
System.Threading.Thread.Sleep(8000);
}