Question

If I use OleDb to connect to a database then use this to capture the info into a datareader -- how could I append this datareader results to a separate query that I am building?

string appendSQL = "";
xxx = new OleDbCommand("Select * from tbl_local, connstring);
dr = xxx.ExecuteReader();
while (dr.Read())
{
  appendSQL = dr["salestatus"].ToString() + ",";
}

---- Separate Query I am building that I want to append the datareader results to:

var qd = new DAO.QueryDef();
qd.SQL = String.Format("Select salesName, saleAmount" + appendSQL + "dateSold from saleDB");

The above shows what I want to do, but when I try that I get multiple errors :(

Was it helpful?

Solution

That syntax as far as a coding standpoint goes looks good. Check your SQL statement and verify there are no issues with your SQL statement. Another solution would be to post the actual errors you are receiving as that will help us narrow down exactly what is causing the issue. As far as the syntax for joining multiple strings together in C# it is below. That would join the values of all three.

qd.SQL = String.Format(appendSQL + appendSQL1 + appendSQL2);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top