【发布时间】:2016-12-01 05:36:07
【问题描述】:
我有一个很长的选择语句,其中包含很多参数和内部连接。
我的第一个问题:有没有办法让它更有效率?
我的第二个问题是为什么它不在文本框中显示任何内容?
我的目标是显示来自搜索的房子。
用户首先选择组合框中的所有内容(所有参数),然后我的选择会遍历表格属性并在文本框中显示可用的房屋
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 Properties.PropertyType=@propertyType AND Properties.City=@city AND Properties.Rooms=@rooms AND Properties.AreaSize=@areasize AND Properties.Price=@price AND Properties.Bathrooms=@bathrooms 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();
【问题讨论】:
-
我会在您的联接之上的数据库中创建一个视图。并从中选择而不是表格。