Datagridview不显示我的数据

时间:2016-12-07 06:23:42

标签: c# asp.net gridview

我正在combobox的数据库中进行搜索,并希望显示在datagridview中。这是要显示的代码。它进入尝试,获取所有信息,但它不显示我的gridview。

mycon = new OleDbConnection(@"...");
protected void btnSubmit_Click(object sender, EventArgs e)
{
    try
    {
         OleDbCommand mycommand = 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.Status = true)", mycon);
         mycommand.Parameters.Add("@propertyType", OleDbType.Integer).Value = cboType.SelectedValue;
         mycommand.Parameters.Add("@city", OleDbType.Integer).Value = cboLocation.SelectedValue;
         mycommand.Parameters.Add("@rooms", OleDbType.Integer).Value = cboBedrooms.SelectedValue;
         mycommand.Parameters.Add("@areasize", OleDbType.Integer).Value = cboSurface.SelectedValue;
         mycommand.Parameters.Add("@price", OleDbType.Integer).Value = cboPrice.SelectedValue;
         mycommand.Parameters.Add("@bathrooms", OleDbType.Integer).Value = cboBathrooms.SelectedValue;            
         mycommand.CommandType = CommandType.Text;
         OleDbDataAdapter myadapt = new OleDbDataAdapter(mycommand);
         myadapt.Fill(myset, "Properties");
         DataTable tbSearchResult = myset.Tables["Properties"];
         GridView1.DataSource = tbSearchResult;
         GridView1.DataBind();        
    }
    catch (Exception)
    {
         ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language = 'javascript'> alert('Sorry no house corresponds to your criterias') </script>");
    }   
}   

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" HorizontalAlign="Center" >
    <AlternatingRowStyle Wrap="False" />
    <EditRowStyle Wrap="False" />
    <HeaderStyle Wrap="False" />
    <RowStyle HorizontalAlign="Center"  />
</asp:GridView>

0 个答案:

没有答案