I have two tables in my database, (Users and Cities) and I want to select all the data in this tables where the column UserID=1 in Users table.
But the Dataset does not find my tables (Users and Cities)
This is my SQL Query:
SELECT * FROM Users INNER JOIN Cities ON Cities.CityID=Users.CityID WHERE Users.UserID=1
And this is the Mathod:
public static DataSet GetData(string SqlQuery)
{
OleDbConnection con = new OleDbConnection(conString);
OleDbCommand cmd = new OleDbCommand(SqlQuery, con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
Code:
DataSet ds = GetData(myQuery);
string fname = ds.Tables["Users"].Rows[0]["UserFisrtName"].ToString();
string lname = ds.Tables["Users"].Rows[0]["UserLastName"].ToString();
string city = ds.Tables["Cities"].Rows[0]["CityName"].ToString();
string output = "Name: " + fname + " " + lname + " City: " + city;