0

I am sending the following SQL query in MS Access 2016 as a string in ASP WebForm:

string showGridViewQuery = "select creditorName, amount, interestRate, interestType, interestCalculationMethod, insertedDate, o.fullName as owner, u.fullName as dataInsertedBy from tbl_savings s left join tbl_users o on ownerID = o.userID left join tbl_users u on dataEnteredByID = u.userID";

When I run, I get the following error:

System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression 'ownerID = o.userID left join tbl_users u on dataEnteredByID = u.userID'.

when the execution reaches showGridViewCommand.ExecuteNonQuery(); in the following code:

string connectionString = GetConnString();
OleDbConnection con = new OleDbConnection(connectionString);
con.Open();
string showGridViewQuery = "select creditorName, amount, interestRate, interestType, interestCalculationMethod, insertedDate, o.fullName as owner, u.fullName as dataInsertedBy from tbl_savings s left join tbl_users o on ownerID = o.userID left join tbl_users u on dataEnteredByID = u.userID";
OleDbCommand showGridViewCommand = new OleDbCommand(showGridViewQuery, con);
showGridViewCommand.ExecuteNonQuery();
DataTable dt = new DataTable();
OleDbDataAdapter olda = new OleDbDataAdapter(showGridViewCommand);
olda.Fill(dt);
GridViewSavingsTracker.DataSource = dt;
GridViewSavingsTracker.DataBind();
con.Close();

What am I missing here?

3
  • what is your database management system, SQL Server, MySQL, MS Access, etc.? Commented Dec 8, 2017 at 12:42
  • I apologize, MS Access 2016 it is. Commented Dec 8, 2017 at 13:45
  • you are joining 2 times to tbl_users. Are you sure you need this? Could pls add table schema definition to your question? Commented Dec 8, 2017 at 13:59

1 Answer 1

0

After a lot of trails, I was able to come to the right solution:

string showGridViewQuery = "select savingsID, creditorName, amount, interestRate, interestType, interestCalculationMethod, insertedDate, o.fullName as owner, u.fullName as dataEnteredBy from ((tbl_savings as s) left join tbl_users as o on s.ownerID = o.userID) left join tbl_users as u on s.dataEnteredByID = u.userID";

I knew MS Access was bad. But didn't know it was THIS bad!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.