0

アクセスに長いクエリがあり、デバッグ中にそれらを確認できるように複数の行にしようとしました。グーグルで見つけた手順を試しましたが、以下の情報で失敗しました。

    public DataSet showallCompanyPaymentbyjobcode(int jobpk ,int confirmquotationpk)
        {

            string query=SELECT companypaymentmastertable.paymentpk, companypaymentmastertable.cmpinvoice, companypaymentmastertable.jobcode, companypaymentmastertable.customercode, confirmquotationmastertable.quotationcode, companypaymentmastertable.customerName, companypaymentmastertable.ischeque, companypaymentmastertable.isCash, companypaymentmastertable.amount, companypaymentmastertable.chequenumber, companypaymentmastertable.bankname, companypaymentmastertable.chequedate, companypaymentmastertable.chequereleasedate, companypaymentmastertable.companypaymentdate
FROM confirmquotationmastertable INNER JOIN companypaymentmastertable ON confirmquotationmastertable.confirmpk=companypaymentmastertable.confirmpk
WHERE (((companypaymentmastertable.confirmpk)=[?]) AND ((companypaymentmastertable.jobpk)=15));


                               OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, Program.ConnStr);
                DataSet ds = new DataSet();
                dAdapter.Fill(ds, "tblpayview");

                if (ds.Tables.Count <= 0)
                {
                    ds = null;    
                }

                return ds;

            }

別のクラスで私はそれを呼んだ

 public void fillpaymenttable()
        {
            DataSet ds= new DataSet();
            ds= companytransaction.showallCompanyPaymentbyjobcode(cmbjobcode.SelectedValue,cmbQuotationcode.SelectedValue);

             tblpaymentview.DataSource = ds.Tables["tblpayview"].DefaultView;

                if (ds.Tables.Count <= 0)
                {
                    lblstatus.Text = "No Payment Details Present";
                    clearcontrols();
                }

            }

クエリを分割する方法はありますか?また、データセットがこのように呼び出された場合にこの関数が機能するかどうかはわかりますか?

4

2 に答える 2

2

実際にコードを別々の行に分割したいだけなら、StringBuilder?を使用します。SQL インジェクションに対して脆弱になるため、パラメーターをクエリに渡す場合はそうではないことに注意してください。

var query = new StringBuilder();

query.Append("SELECT companypaymentmastertable.paymentpk, companypaymentmastertable.cmpinvoice, ");
query.Append("companypaymentmastertable.jobcode, companypaymentmastertable.customercode, ");
query.Append("confirmquotationmastertable.quotationcode, companypaymentmastertable.customerName, ");
query.Append("companypaymentmastertable.ischeque, companypaymentmastertable.isCash, ");
query.Append("companypaymentmastertable.amount, companypaymentmastertable.chequenumber, ");
query.Append("companypaymentmastertable.bankname, companypaymentmastertable.chequedate, ");
query.Append(" companypaymentmastertable.chequereleasedate, companypaymentmastertable.companypaymentdate ");
query.Append("FROM confirmquotationmastertable INNER JOIN companypaymentmastertable ");
query.Append("ON confirmquotationmastertable.confirmpk=companypaymentmastertable.confirmpk ");
query.Append("WHERE (((companypaymentmastertable.confirmpk)=[?]) ");
query.Append("AND ((companypaymentmastertable.jobpk)=15))");
于 2012-04-17T17:56:27.590 に答える
1

文字列の連結は実行時ではなくコンパイル時に実行されるため、これは stringbuilder を使用するよりも効率的です。

string query="SELECT companypaymentmastertable.paymentpk, companypaymentmastertable.cmpinvoice, "
 + "companypaymentmastertable.jobcode, companypaymentmastertable.customercode, "
 + "confirmquotationmastertable.quotationcode, companypaymentmastertable.customerName, "
 + "companypaymentmastertable.ischeque, companypaymentmastertable.isCash, companypaymentmastertable.amount, "
 + "companypaymentmastertable.chequenumber, companypaymentmastertable.bankname, companypaymentmastertable.chequedate, "
 + "companypaymentmastertable.chequereleasedate, companypaymentmastertable.companypaymentdate "
 + "FROM confirmquotationmastertable INNER JOIN companypaymentmastertable ON "
 + "confirmquotationmastertable.confirmpk=companypaymentmastertable.confirmpk "
 + "WHERE (((companypaymentmastertable.confirmpk)=[?]) AND ((companypaymentmastertable.jobpk)=15));"

または、「逐語的な文字列」を使用できます。

    string query= @"SELECT companypaymentmastertable.paymentpk, companypaymentmastertable.cmpinvoice, 
companypaymentmastertable.jobcode, companypaymentmastertable.customercode, 
confirmquotationmastertable.quotationcode, companypaymentmastertable.customerName, 
companypaymentmastertable.ischeque, companypaymentmastertable.isCash, companypaymentmastertable.amount, 
companypaymentmastertable.chequenumber, companypaymentmastertable.bankname, companypaymentmastertable.chequedate, 
companypaymentmastertable.chequereleasedate, companypaymentmastertable.companypaymentdate    
FROM confirmquotationmastertable 
INNER JOIN companypaymentmastertable ON confirmquotationmastertable.confirmpk=companypaymentmastertable.confirmpk    
WHERE (((companypaymentmastertable.confirmpk)=[?]) AND ((companypaymentmastertable.jobpk)=15));";
于 2012-04-17T19:14:21.170 に答える