Click here to Skip to main content
15,886,544 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
if (!IsPostBack)
       {
           string ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/Database/registration.accdb");
           using (OleDbConnection con = new OleDbConnection(ConnectionString))
           {
               OleDbDataAdapter da = new OleDbDataAdapter("SELECT A.*,B.*,C.* FROM [size] A inner join [tblcategory] B on B.catid =A.catid inner join [subcategory] C on C.subcatid = A.subcatid ", con);
               DataSet ds = new DataSet();
               da.Fill(ds);
               rptrsize.DataSource = ds;
               rptrsize.DataBind();
           }
       }


What I have tried:

how to correct this query please solve briefly and help me
Posted
Updated 18-Aug-21 21:34pm
Comments
Wendelius 18-Aug-21 0:10am    
What is the error you're getting?
Kaise karen? 18-Aug-21 0:17am    
SELECT A.*,B.*,C.* FROM [size] A inner join [tblcategory] B on B.catid =A.catid inner join [subcategory] C on C.subcatid = A.subcatid this query is not working my database is in ms-access
error is in aspx code:
Line 87:  <%# Eval("sizename") %>
Line 88: Line 89: <%# Eval("catname") %> //error is here
Line 91: <%# Eval("subcatname") %>Error description: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'catname'.

Based on the error message the error is not raised when executing the query. Instead it seems that binding is incorrect.

Re-check all the column names on the tables you have used in your query (size, tblcategory, and subcategory) and ensure that those column names match exactly the names you have used in binding.

Also note that if you have same column names in multiple tables you may encounter problems. In general I prefer selecting explicit columns instead of using asterisk. This for example enhances code readability and prevents unneeded data from being transferred.

For example, instead of
SQL
SELECT a.*
FROM TableName a

Something like
SQL
SELECT a.Column1,
       a.Column2
FROM TableName a

And if renaming the columns is needed, something like
SQL
SELECT a.Column1 AS MyCol1,
       a.Column2 AS MyCol2
FROM TableName a
 
Share this answer
 
Comments
Kaise karen? 18-Aug-21 1:16am    
thanks, buddy for the solution but it's didn't working my database is in ms-access. Already bind two database tables in another project working fine. but this one creates an error every time I'll do to improve the query. can you please write a correct query for a reference
Richard Deeming 18-Aug-21 5:10am    
We don't have access to your database, we can't see the structure of your tables, and we don't know what columns you need to display.

Nobody can "write a correct query" for you. You need to follow Wendelius' advice, and write the correct query for yourself.
Wendelius 18-Aug-21 11:02am    
Binding is not the same as joining. In your query you join the tables but once you have fetched the data, you bind it to the user interface, that's when the problem occurs.

It's easy to test, comment out the following line from your code

rptrsize.DataBind();

Now when you run the program it probably runs okay but no data is shown in UI. This happens because now you haven't set the data source and binding does not happen. If you add the row back, the error occurs.

If this is correct, then it proofs that the problem is a mismatch between the data column names (the column in the data table) and the names used in UI binding (Eval("catname")). In other words, there is no column catname in the data table.
MS Access database engine is very specific.... When you use multiple joins, you need to use brackets, lie this:

2 joins:
SQL
SELECT ...
FROM (origintable
JOIN jointable1 ON ...)
JOIN jointable2 ON ...


3 joins
SQL
SELECT ...
FROM ((origintable
JOIN jointable1 ON ...)
JOIN jointable2 ON ...)
JOIN jointable3 ON ...


And so on...
 
Share this answer
 

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