Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Basically, i have to perform a search where i want to show all the upcoming events for a member on a datagrid.

The hard part is that, the SpecialMoment table is where all the events are, including the MomentDateTime (which is where i was going to do >= GETDATE() to show all events upcoming from the current date). But another hard part is that the MemberMomentNo number is in the MemberMoment table.

Basically i want to show this in the grid:

MomentName, MomentDateTime - All in the SpecialMoment table
MemberID, MemberMomentNo - All in the MemberMoment table.


Im basically combing a searching through 2 tables.




I need help thanks
Posted
Comments
Maciej Los 26-Feb-14 17:40pm    
What have you done till now? Where are you stuck? Improve your question and add details, at least: the structure of tables, sample data and expected output.
ZurdoDev 26-Feb-14 19:43pm    
Where are you stuck? It's just a simple join if there is a relationship between the 2 tables.
[no name] 26-Feb-14 19:47pm    
I'm not sure, its really difficult to explain. I thought it would be a simple join, but wouldnt that cause problems when trying to to the SQL statement in an SQLCommand in C#?

1 solution

Let spell out the scenario:
2 tables:
table: membermember, at least 2 fields: memberid, membermomentno, ...
table: moment, at least 2 fields: momentno, momentname, ...
membermomentno field is linked to momentno
Say you want to draw data from this 2 tables and populate a datagrid. Adapt the following code to suit your needs:
on the aspx page:
XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   <ASP:DataGrid id="MyDataGrid" runat="server"
      Width="800"
      BackColor="#cccccc"
      BorderColor="black"
      ShowFooter="false"
      CellPadding="5"
      CellSpacing="5"
      Font-Name="Verdana"
      Font-Size="12pt"
      HeaderStyle-BackColor="#abcdef"
      EnableViewState="false"
   />
    </div>
    </form>
</body>
</html>


on the code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Default8 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\Peter Leow\Documents\Visual Studio 2010\Projects\SampleDatabaseWalkthrough\SampleDatabaseWalkthrough\SampleDatabase.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True");
        SqlDataAdapter myCommand = new SqlDataAdapter("SELECT memberid, momentname FROM membermoment JOIN moment ON membermomentno = momentno", myConnection);
        DataSet ds = new DataSet();
        myCommand.Fill(ds);
        DataView source = new DataView(ds.Tables[0]);
        MyDataGrid.DataSource = source;
        MyDataGrid.DataBind();
    }
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900