I have tryed the above and get the following error:
System.InvalidOperationException: ExecuteScalar requires an open and available Connection. The connection's current state is closed.
at System.Data.SqlClient.SqlConnection.GetOpenConnection(String method)
at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteScalar()
at NavisionLink.NavisionLink.GetPONumber(String Database) in D:\MyDev\NavisionLink\NavisionLink.asmx.cs:line 283
Copy of the code now:
public String GetPONumber(string Database)
{
SqlConnection sqlConn = new SqlConnection(GetConnString(Database));
sqlConn.ConnectionString = GetConnString(Database);
SqlCommand command = sqlConn.CreateCommand();
command.CommandType = CommandType.Text;
command.CommandText = @" Query Here!! ";
object returnValue = command.ExecuteScalar();
command.Dispose();
return returnValue.ToString();
}