如何在C#中编写这个sql查询? [英] how to write this sql query in C#?
问题描述
我有两个表1.custTransaction和2.custDetails
我想显示其限制(来自custDetails)比Due Amount(来自custTransaction)表更新的客户。我提供客户ID来自textBox。
custTransaction表结构是 - :
字段名称 - >数据类型
=========================
custID - >文本
custTranDate - > datetime
custTranType - >文本
custPaidAmt - >号码
custDueAmt - >数字
custDetails表结构是 - :
字段名称 - >数据类型
=========================
custID - >文字
custName - >文字
custAdd - >文字
custLimit - >号码
我的sql查询是 - :
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 -:
SELECT custName, custAdd, custPho
FROM custDetails, custTransaction
WHERE custTransaction.custID='"+textBox1.text+"' and custTransaction.custDueAmt < custDetails.custLimit;
我使用=> MSAccess。
如何在C#中编写查询应用程序???
I used => MSAccess.
how to write the query in C# Application???
推荐答案
希望这个Helps.Just复制和粘贴。
Hope This Helps.Just copy and paste.
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)
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();
这篇关于如何在C#中编写这个sql查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!