Camillia
asked on
Code works but breaks when I add one section
This is VS 2013/C#/ Web Forms. I need to make a change to this code that was done by a developer who was fired.
I think I know what the issue is but I don't know how to fix it. I can't use a stored proc for it otherwise, it wouldn't be that hard.
This is the code
This works
2. Now, I want to add a temp table to that SQL but I get an error "error near Select". How can I run a SQL statement with a temp table in it in C#?
I think I know what the issue is but I don't know how to fix it. I can't use a stored proc for it otherwise, it wouldn't be that hard.
This is the code
This works
public static List<EmailDomainModels> GetInfo(...)
{
System.Text.StringBuilder sql = new System.Text.StringBuilder(@"
select * from mytable ");
....
string connName = "some connection";
using (IDataReader dr = BSSQLConnection.ExecSQL(connName, sql)
{
while (!dr.IsClosed && dr.Read()
{
......
}
}
}
//This is ExecSQL(
public static IDataReader ExecSQL(string dbName,string sql)
{
BSSQLConnection db = new BSSQLConnection(dbName);
return db.GetDataReader(sql)
}
//This is GetDataReader
public IDataReader (string sql)
{
return GetDataSet(sql).CreateDataReader();
}
//This is GetDataSet
public DataSet GetDataSet(string sql)
{
DBCommand cmd = ...
return DB.ExecuteDataSet(cmd);
}
2. Now, I want to add a temp table to that SQL but I get an error "error near Select". How can I run a SQL statement with a temp table in it in C#?
public static List<EmailDomainModels> GetInfo(...)
{
System.Text.StringBuilder sql = new System.Text.StringBuilder(@"
create table #results
(
id int,
name varchar(10)
)
Go
select * from mytable ");
ASKER
I don't think that would work...
1. I create the temp table
var temp = "@
...temp table code here
";
C# execute SQL here? if so, use executescalar?
2. Populate the temp table
execute SQL here but would the temp table be out of scope here??
1. I create the temp table
var temp = "@
...temp table code here
";
C# execute SQL here? if so, use executescalar?
2. Populate the temp table
execute SQL here but would the temp table be out of scope here??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, let me see
1 - create temp table
2 - populate it
INSERT INTO #results(id,name)
SELECT id, name
FROM mytable
Something like that...