Click here to Skip to main content
15,063,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how to joined two tables
i have a document info table

docid
docname
uploadfile
docid
depid


and approvetype table

approveid
approvetype


i use this query

SQL
SELECT DocumentInfo.DocID,
   dbo.DocumentInfo.DocName,
   dbo.DocumentInfo.Uploadfile,
   dbo.DocType.DocType,
   dbo.Department.DepType ,
   dbo.ApproveType.ApproveType AS ApproveID
FROM dbo.DocumentInfo 
LEFT JOIN dbo.DocType ON dbo.DocumentInfo.DocTypeID=dbo.DocType.DocTypeID 
LEFT JOIN dbo.Department ON dbo.DocumentInfo.DepID=dbo.Department.DepID 



and it shows me error

C#
The multi-part identifier "dbo.ApproveType.ApproveType" could not be bound.
Posted
Updated 3-Oct-13 21:27pm
v2
Comments
[no name] 4-Oct-13 3:15am
   
Share the expected output structure.
Diya Ayesa 4-Oct-13 3:16am
   
i try to add dropdownlist in grdiview ....through following grdiview code
<asp:BoundField HeaderText="ApproveID" DataField="ApproveID">
<asp:TemplateField>
<itemtemplate>
<asp:DropDownList ID="DropDownList4" runat="server" class="vpb_dropdown">

Diya Ayesa 4-Oct-13 3:17am
   
and c# code is
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Find the DropDownList in the Row
DropDownList ddlCountries = (e.Row.FindControl("DropDownList4") as DropDownList);
ddlCountries.DataSource = GetData("SELECT ApproveID,ApproveType FROM ApproveType");
ddlCountries.DataTextField = "ApproveType";
ddlCountries.DataValueField = "ApproveID";
ddlCountries.DataBind();

//Add Default Item in the DropDownList
ddlCountries.Items.Insert(0, new ListItem("Please select"));

//Select the Country of Customer in DropDownList
//string country = (e.Row.FindControl("lblCountry") as Label).Text;
//ddlCountries.Items.FindByValue(country).Selected = true;
}
}


and i view the documents in grdiview through page laod

pageload code

GrdFileApprove.DataSource = dd.gdocid();
GrdFileApprove.DataBind();



Diya Ayesa 4-Oct-13 3:19am
   
when i debug the code it show me error
A field or property with the name 'ApproveID' was not found on the selected data source.

Hi, you didn't join the ApproveType Table in your query.

SQL
SELECT DocumentInfo.DocID,
   dbo.DocumentInfo.DocName,
   dbo.DocumentInfo.Uploadfile,
   dbo.DocType.DocType,
   dbo.Department.DepType ,
   dbo.ApproveType.ApproveType AS ApproveID
FROM dbo.DocumentInfo 
LEFT JOIN dbo.DocType ON dbo.DocumentInfo.DocTypeID=dbo.DocType.DocTypeID 
LEFT JOIN dbo.Department ON dbo.DocumentInfo.DepID=dbo.Department.DepID 


You must join it in order to see the ApproveType column.

Hope it helps! :)
   
v2
Comments
Diya Ayesa 4-Oct-13 3:33am
   
it shows me error
The multi-part identifier "dbo.ApproveType.ApproveType" could not be bound.
Diya Ayesa 4-Oct-13 3:34am
   
there is no approveid in document info table
chimcham 4-Oct-13 3:38am
   
Hi Ayesha, maybe you could use the DocumentInfo.DocID or the dbo.Department.DepID or any ID that you can link to your ApproveType Table.

Note: You need to link the ApproveType Table so that ApproveType column is visible in your query.
You didn't include(join) the table ApproveType in your query & you're trying to select a column from that table, so it raised that exception.
I think you can't execute that query, surely the DB'll raise the same error.
You have to change the query based on your requirement.
   
SELECT DocumentInfo.DocID,
dbo.DocumentInfo.DocName,
dbo.DocumentInfo.Uploadfile,
dbo.DocType.DocType,
dbo.Department.DepType ,
dbo.ApproveType.ApproveType AS ApproveID
FROM dbo.DocumentInfo
LEFT JOIN dbo.DocType ON dbo.DocumentInfo.DocTypeID=dbo.DocType.DocTypeID
LEFT JOIN dbo.Department ON dbo.DocumentInfo.DepID=dbo.Department.DepID
LEFT JOIN dbo.ApproveType ON dbo.ApproveType.approveid=dbo.Department.DepID
   
Comments
RKM1128 4-Oct-13 3:37am
   
Try to join all the table according your requirement

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