开发者

direct SQL execution to get count using Enterprise library

I am new to asp.net development and using enterprise library in my application in the following way.

 Database db = DatabaseFactory.CreateDatabase();

            DbCommand cmd = db.GetStoredProcCommand("sp_MakePayment");

            db.AddInParameter(cmd, "@BillGenID", System.Data.DbType.Int32);
            db.SetParameterValue(cmd, "@BillGenID", billgenID);

            db.AddInParameter(cmd, "@PayDate", System.Data.DbType.String, 50);
            db.SetParameterValue(cmd, "@PayDate", mypaydate.Text);

            db.AddInParameter(cmd, "@TransNo", System.Data.DbType.String, 50);
            db.SetParameterValue(cmd, "@TransNo", transno.Text);

            db.AddInParameter(cmd, "@AmtToPay", System.Data.DbType.Double);
            db.SetParameterValue(cmd, "@AmtToPay", Convert.ToDouble(paidamount.Text));


            ////Execute Stored Procedure
            int i = 0;
            i = db.ExecuteNonQuery(cmd);

Now I am in a situation where i need to run this inlnie query using the same method to get the count of records and read in a variable. for example following query to find existing bill.

string bill_id = "1234";
string dofpayment = "11/03/2011";

 mysql = "Select count(*) from p开发者_高级运维ayments where bill_id = " + bill_id + " and payment_date = " + dofpayment ;

Now how to incorporate the above lines using the enterprise library block.

thanks


If you enterprise library supports text commands alongside with stored procedures, then you should write a code which creates a text command and then passes your bill_id and dofpayment as parameters to it.

Otherwise, you need to create a stored procedure with these two parameters and then call that in similar way shown in your code example for stored procedure.

I hope this helps!


string sSql = "SELECT CustomerID, CompanyName, City, Country" + " FROM Customers WHERE Country = @sCountry"; Database db = DatabaseFactory.CreateDatabase(); DBCommandWrapper cmd = db.GetSqlStringCommandWrapper(sSql); cmd.AddInParameter("@sCountry", DbType.String, sCountry); DataSet ds = new DataSet(); db.LoadDataSet(cmd, ds, "Customers");

please read the msdn reference

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜