Click here to Skip to main content
15,885,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have two tables 1.custTransaction and 2.custDetails
I want to display the customer whose limit(from custDetails) are getter than Due Amount ( from custTransaction) tables.I provide the customer ID from a textBox.
custTransaction table structure is-:

fields Name -> Data type
=========================
custID -> text
custTranDate -> datetime
custTranType -> text
custPaidAmt -> number
custDueAmt -> number

custDetails table structure is -:
fields Name -> Data type
=========================
custID -> text
custName -> text
custAdd -> text
custLimit -> number


My sql Query is -:
SQL
SELECT custName, custAdd, custPho
FROM custDetails, custTransaction
WHERE custTransaction.custID='"+textBox1.text+"' and custTransaction.custDueAmt < custDetails.custLimit;

I used => MSAccess.
how to write the query in C# Application???
Posted
Updated 25-Feb-13 3:08am
v2
Comments
Shubh Agrahari 25-Feb-13 9:09am    
whats happening with your SELECT custName, custAdd, custPho
FROM custDetails, custTransaction
WHERE custTransaction.custID='"+textBox1.text+"' and custTransaction.custDueAmt < custDetails.custLimit; this code what error occurring...?
[no name] 25-Feb-13 9:12am    
What is it the you are trying to do? Queries are written in SQL just like you have, not in C#.
JayantaChatterjee 25-Feb-13 9:18am    
It doesn't show the specific records???
CHill60 25-Feb-13 9:22am    
If you pick a sample custID and run the query directly in Access what results do you get
[no name] 25-Feb-13 9:25am    
Is custID an int or text?

Hope This Helps.Just copy and paste.
SQL
SELECT     dbo.custDetails.custID AS Expr1, dbo.custDetails.custName, dbo.custDetails.custLimit, dbo.custTransaction.custDueAmt
FROM         dbo.custTransaction INNER JOIN
                      dbo.custDetails ON dbo.custTransaction.CustId = dbo.custDetails.custID
WHERE     (custDetails.custLimit > dbo.custTransaction.custDueAmt)
 
Share this answer
 
Comments
JayantaChatterjee 25-Feb-13 10:11am    
Sir I want to give the custID through textBox.
where I put the textBox value in this query???
Maksud Saifullah Pulak 25-Feb-13 10:20am    
SELECT dbo.custDetails.custID AS Expr1, dbo.custDetails.custName, dbo.custDetails.custLimit, dbo.custTransaction.custDueAmt
FROM dbo.custTransaction INNER JOIN
dbo.custDetails ON dbo.custTransaction.CustId = dbo.custDetails.custID AND dbo.custTransaction.custDueAmt < dbo.custDetails.custLimit
WHERE (dbo.custDetails.custID ='"+textBox1.text+"')
Maksud Saifullah Pulak 25-Feb-13 10:22am    
Just exactly paste this code and check the syntex.
JayantaChatterjee 25-Feb-13 10:30am    
its works, but it return the multiple row, which depend on custTransaction tables records....
I want Only one row..
JayantaChatterjee 25-Feb-13 10:36am    
My final query is -:
SELECT top 1 custDetails.custID AS Expr1, custDetails.custName,custDetails.custPho,custDetails.custAdd FROM custTransaction INNER JOIN custDetails ON custTransaction.CustId = custDetails.custID AND custTransaction.custDueAmt < custDetails.custLimit WHERE (custDetails.custID ='"+textBox1.text+"')
Thanks a lottttttttttttttt Sir for Helping meee.... :-)
C#
SqlConnection sqlConnection = new SqlConnection( "Data Source=localhost;Initial Catalog=databasename;Integrated Security=true;" );
					SqlCommand command = sqlConnection.CreateCommand();
					sqlConnection.Open();
					command.CommandTimeout = 0;
					command.CommandText = "SELECT custName, custAdd, custPho FROM custDetails, custTransaction WHERE custTransaction.custID='" + textBox1.text + "' and custTransaction.custDueAmt < custDetails.custLimit;";
					SqlDataReader reader =  command.ExecuteReader();
					while( reader.Read() )
					{
						reader [ 0 ].ToString() + "," + reader [ 1 ].ToString() + "," + reader [ 2 ].ToString() + Environment.NewLine;
					}
					reader.Close();
 
Share this answer
 
v2
Comments
JayantaChatterjee 25-Feb-13 10:13am    
You write the same query,which I written. This is not the solution,It doesn't show the correct records...

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