You must Sign In to post a response.
  • Category: .NET

    Display the Data in DataGridView using Join query

    Hi,

    I want to show the multiple table data in datagridview where the Student ID is matching in all table.
  • #712963
    Hi,

    Take a view in design mode add the tables you want Join then you will get the Query beneath and execute it.It is giving it ur expected output copy the query.

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #712968
    Hi,

    I am using MS Access 2007 not SQL. I have tried the below code it working fine. But most of the records are in blank. I could not show this in datagridview. I should show only the full filed records.

    Where Bill_Date value is blank that record would not show in DataGridView.

    adp = new OleDbDataAdapter("Select CurrentFees_Month.Admission_No, CurrentFees_Month.Bill_Date, CurrentFees_Cocuri.Yoga_Fee CurrentFees_Cocuri.Karathe from CurrentFees_Month Inner Join currentfees_cocuri ON CurrentFees_Month.Admission_No = CurrentFees_Cocuri.Admission_No ", conn);

    ds = new DataSet();

    adp.Fill(ds, "CurrentFees_month_CurrentFees_Cocuri");

    dataGridView1.DataSource = ds.Tables[0];

    What i want to do here to prevent the blank record...

    -----------------------------------------------------------------------------
    Regards,
    Gopi A.
    +91 9894315571
    Skype:gopi.net
    http://asaigopi-dotnet.blogspot.in/

  • #712969
    Hi Gopi ,

    You can keep where condition for this.Bill_Date is not null

    Hope Your search ends here

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #712979
    Hi,
    You have to build your sql query according to join multiple tables
    Let's consider an example on Employee records. Have Employee table with Empid , Empname, DeptID columns and Dept table which has dept id and deptname columns
    One more table called Payroll table which has EmpID, Salarydetails like Basic, DA, HRA,..any deductions….
    Lets prepare a query for getting all the information



    Select E.EmpID, E.EmpName,D.Deptname,S.Basic,S.DA,S.Deductions from Employee E left outer join Depttable on E.DeptId=D.DeptID
    Leftouter join Salarytable S on E.EmpID=S.EmpID



    Now you can bind the result set to Gridview
    Thanks
    Padma

    Have a good Day

  • #712987
    Hi Padma,

    The above my query is working fine as well as yours. But i want to hide the blank columns. That where the Bill_Date column is blank that row should be hide.

    Hi Srirama,

    The "NULL" is not working in C#. I hope it is working in SQL, but i dont know how to handle this in C#. Can you help me.

    -----------------------------------------------------------------------------
    Regards,
    Gopi A.
    +91 9894315571
    Skype:gopi.net
    http://asaigopi-dotnet.blogspot.in/

  • #713003
    after binding the data, and check for empty columns and hide in gridview.see the sample code. change the table and column name accordingly.


    List<string> lstEmptColumns = new List<string>();

    foreach (DataColumn col in dtSource.Columns)
    {
    bool isEmpty = true ;
    foreach (DataRow row in dtSource.Rows)
    {
    if (row[col] != DBNull.Value)
    {
    isEmpty = false;
    break;
    }

    }
    if (isEmpty)
    {
    lstEmptColumns.Add(col.ColumnName);
    }
    }

    dataGridView1.DataSource = dtSource;

    foreach (string str in lstEmptColumns)
    {
    dataGridView1.Columns[str].Visible = false;
    }

    Regards,
    Shine

  • #713006
    Hi Gopi ,

    Its working I tested in mS-ACCESS DATA BASE .IS NOT NULL

    ELSE TRY THIS

    SELECT Student.[ID], Student.[Name], Student.[DOJ]
    FROM Student WHERE DOJ <> 01/01/1900

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #713013
    Hi gopi

    Had you checked it i am sending the access file

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

    New-Microsoft-Office-Access-2007-Dat

    Delete Attachment

  • #713117
    hi gopi try this


    adp = new OleDbDataAdapter("Select CurrentFees_Month.Admission_No, CurrentFees_Month.Bill_Date, CurrentFees_Cocuri.Yoga_Fee CurrentFees_Cocuri.Karathe from CurrentFees_Month Inner Join currentfees_cocuri ON CurrentFees_Month.Admission_No = CurrentFees_Cocuri.Admission_No Where Bill_Date IS NOT NULL", conn);


    just include is not null condition in the where clause

    Regards,
    Chethan

  • #713275
    Use View in Sql . And Reflect in Front End in Grid View.
    Regards
    Rakesh Chaubey
    rakeshchaubey1989@gmail.com

  • #715502
    Hi,


    Using Joins you can achieve this .
    Go through the below link for more information about joins
    http://blog.sqlauthority.com/2009/04/13/sql-server-introduction-to-joins-basic-of-joins/

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.