1
我有一個很長的select語句,它有很多參數和Inner join。有很多連接和參數的SQL語句
我的第一個問題:有沒有辦法讓它更有效率?
我的第二個問題是爲什麼它不顯示文本框中的任何東西?
我的目標是顯示來自搜索的房子。
用戶首先選擇在組合框中的一切(所有參數),然後我選擇穿過表屬性,並在文本框中顯示可用的房屋
clsDataSource.mycon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\...");
clsDataSource.mycon.Open();
OleDbCommand mycmd = new OleDbCommand("SELECT AreaSize.*, Bathrooms.*, Cities.*, Prices.*,Properties.*, Rooms.*, Types.*, Users.* FROM Users INNER JOIN (Types INNER JOIN (Rooms INNER JOIN (Prices INNER JOIN (Cities INNER JOIN (Bathrooms INNER JOIN (AreaSize INNER JOIN Properties ON AreaSize.AreaSizeID = Properties.AreaSize) ON Bathrooms.BathroomID = Properties.Bathrooms) ON Cities.CityID = Properties.City) ON Prices.PriceID = Properties.Price) ON Rooms.RoomID = Properties.Rooms) ON Types.TypeID = Properties.PropertyType) ON Users.UserID = Properties.AgentID WHERE [email protected] AND [email protected] AND [email protected] AND [email protected] AND [email protected] AND [email protected] AND (Properties.BoolAgent = true)", clsDataSource.mycon);
mycmd.Parameters.Add("@city", OleDbType.Integer, 3).Value = clsHouses.location;
mycmd.Parameters.Add("@propertyType", OleDbType.Integer, 3).Value = clsHouses.type;
mycmd.Parameters.Add("@rooms", OleDbType.Integer, 3).Value = clsHouses.bedrooms;
mycmd.Parameters.Add("@areasize", OleDbType.Integer, 3).Value = clsHouses.surface;
mycmd.Parameters.Add("@price ", OleDbType.Integer, 3).Value = clsHouses.price;
mycmd.Parameters.Add("@bathrooms", OleDbType.Integer, 3).Value = clsHouses.bathrooms;
myadaptS = new OleDbDataAdapter(mycmd);
myadaptS.Fill(clsDataSource.myset, "ResultSearch");
tbSearchResult = clsDataSource.myset.Tables["Properties"];
txtType.Text = tbSearchResult.Rows[idx]["DescriptionType"].ToString();
我會做一個視圖在你的連接之上的數據庫中。並從中選擇而不是表格。 – user1681317