I have a .sql script that contain the following code
-- Drop stored procedure if it already exists
USE Temp
IF EXISTS (
SELECT *
FROM INFORMATION_SCHEMA.ROUTINES
WHERE SPECIFIC_SCHEMA = N'Custom'
AND SPECIFIC_NAME = N'RestoreVersion'
)
DROP PROCEDURE Custom.RestoreVersion
GO
CREATE PROCEDURE Custom.RestoreVersion
@ID INT
AS
SELECT * FROM [App].[Version] WHERE ID = @ID
DROP PROCEDURE Custom.RestoreVersion
GO
EXECUTE Custom.RestoreVersion @ID = [ID from c# program]
GO
I would like to take this file and set the @ID parameter in c# and then run the sql script.
I want this script to live in a folder on my application but I can't get it to work.
I tried this.
Console.Write(Server_Name + Environment.NewLine);
connectSqlServer(Server_Name);
SqlDataReader rdr = null;
Console.WriteLine("\nGet Version\n");
try
{
SqlCommand cmd = new SqlCommand("Custom.RestoreVersion", conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@ID", ID));
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine(Values);
}
}
finally
{
if (conn != null)
{
conn.Close();
}
if (rdr != null)
{
rdr.Close();
}
}
However I am unable to get this to read the file from the Resources folder and enter the parameters to the database.