Refactoring A Method To Replace Sql String With The Stringbuilder Class
Nov 3, 2010
How do I refactor the method GetInvoiceNumbers to replace the SQL String concatenation with the StringBuilder class? Here is my code:
Private Function GetInvoiceNumbers() As System.Collections.Generic.List(Of Invoice) Implements InvoiceService.GetInvoiceNumbers
Dim invoiceList As New List(Of Invoice)
I am facing an amazing problem in my application. On my Developement server when I am running my application, then there is one function where I am trying to put whole stringbuilder contents in a string object. This Function is used for paging the reports.For that I am using a method of Stringbuilder.tostring() and when I chek the value of this statement (stringbuilder.tostring()) it shows no such interface is supported, which later on throws exception of system is out of memory. Here i am using .net 2.0 framework and sql server 2005 database.But when I run the application on stagging server then there is no such exception thrown.[code]
'strSearch = textBox.Text, columns 2 to 10 are the optional columns you want to search to. Function WhereQuery(ByVal strSearch As String, ByVal column1 As String, Optional ByVal column2 As String = "", Optional ByVal column3 As String = "", Optional ByVal column4 As String = "", Optional ByVal column5 As String = "", Optional ByVal column6 As String = "", Optional ByVal column7 As String = "",[code]..
sample output:
im also thinking on using stringbuilder to replace my strings.
I need to refactor the method GetVendorBalanceDue to call stored procedure spVendorBalance in my database. I have created the stored procedure and am not sure how to get the method to call the stored procedure. Here is my code:
Private Function GetVendorBalanceDue(ByVal vendorID As Integer) As Decimal Implements InvoiceService.GetVendorBalanceDue Dim selectCommand As New SqlCommand
eg: dim classobj = xyz("CLASS_NAME") ' where classname is a valid class name and dynamically raising a known method of that class on that newly created object or class reference.
I am using .net 2.0 and I am getting an exception of system is out of memory. My existing function takes datatable as input parameter which contains little bit large data (eg. more than 35000 rows) and in that function I am appending some xml node data and atlast I am returning the stringbuilder as a object.
I recently started a project and needed to do some integration with LDAP via DirectoryServices. I've done this in other apps so I went into one of them to see how I did it -- why reinvent the wheel right? Well, while this wheel works, it was developed years ago and kinda smells (it's wooden, firmly attached to the previous vehicle, hard to repair and produces a potentially bumpy ride).So I thought to myself, this is the perfect time to refactor this puppy and make it more portable, reusable, reliable, easier to configure etc. Now that's fine and dandy, but then I started feeling a tad overwhelmed regarding to where to start. Should it be a separate library? How should it be configured? Should it use IoC? DI?
So my [admittedly subjective] question is this -- given a relatively small, but quite useful class like the one below, what is a good approach to refactoring it? What questions do you ask and how do you decide what to implement or not implement? Where do you draw the line regarding configuration flexibility? [Note: Please don't bash this code too much okay? It was written a long time ago and has functioned perfectly well baked into an in house application.]
Public Shared Function AuthenticateUser(ByVal id As String, ByVal password As String) As Boolean Dim path As String = GetUserPath(id)
This is my scenario. I am writing an app which takes a person object and a features object , when the user selects a person object a features object is created. This works for any amount of features i care to display. So far so good, i am now refactoring to create 2 additional classes, a maths class and a ui class. my issue now is how do i get the maths functions to know the instance of the features object(s) or person object(s)?
Unfactored Public Sub New(ByVal feature1 As New Feature) ...
I'm using VB's StringBuilder, and I was curious what is considered "best practice" for emptying the builder/setting it to a new string. Would it be something like this:[code]or is there a "Better" way?
Consider a MyForm class that contains a shadowed implementation of Show(). It also contains a CreateForm() method, which accepts an instance of the form and calls the shadowed sub:
Dont understand where to start on visual basic iv been leaning alot about computers over the months and i would now like to design a program and to be honest its all new and i dont no where to start or what any of these woulds mean like string, data enadled application and refactoring.
I'm currently refactoring an old Visual Basic DLL (VB.Net), which stores all of its data in one module called Globaldefinitions as public fields. There are about 200 fields, referenced thousands of times all around the code:
Public Module Globaldefinitons Public a As Short ... Public zz10 As Double
[Code]...
I need to change the module into a class with non-shared fields. This means, each and every of these thousands of references needs to reference the instance of that class:
globalDefinitionsInstance.a = 5
How do I go about this efficiently?
Regular expressions operating on the source fall flat. Refactoring tools like Re-Sharper or CodeRush don't seem to offer this functionality. Visual Studio 2010 cannot do it automatically either.
The file reads in parameters and two of the parameters used to be in Date Format YYYYMMDD but will now permanently be in format YYYY-MM-DD. This change, I believe, is stopping the import of the file from working. I would like to replace the new format YYYY-MM-DD back to YYYYMMDD in the code. If possible I'd also like to see some output so I know that the old format has been replaced with the new format. The code is below. I added the two rows with .replace code in green in expecting that to be enough but it is still not working.
Public Sub Main() Dim R1, O1, P1, C1, strDateFrom, strDateTo, strRunDate As String
Public Class Form1 Dim x As String 'TCC ENCYRTION CODE, COPY RIGHT OF T.C co Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
[code]....
i want to change ALL the a's in the programs textbox1 to b's when the encryption button is clicked (button 1), remember when it is click it determines weather the text in textbox1.text is more then five, if so it goes onto replacing the a's if not, then it shows a error message?
Supose i have two TextboxOne For normal Text and Second For After Replace textif i m Type some text in textbox 1 then Textbox2 show Its Replacement Text
I am using following code to replace the passwords in my app.config. It replaces successfully but does not reload config file in the memory so datasets give error of wrong password.
Dim vrTextFind As String = "Password" Dim vrTextReplaceWith As String = "PWD" Dim path As String = "D:VS2008EncTestEncTestinDebugenctest.exe.config"
I've been creating short test apps repeatedly to try to understand some of the concepts in VB.NET.For the most part it has been illuminating.I read Bucky's .NET knowlegebase tutorial on passing objects as parameters to newly created forms. He shows how to create a new class that inherits from the base form class and define a New() method with parameters Extending the concept I thought about doing the same thing with a form that was created at design-time (In this case Form2).
Base class has one field to hold numeric balance value. With 2 methods that accept arguments for adding and subtracting the new input calculating new balance. Sub class has four fields dates, transaction, memo and amount.I have a deposit form, and withdraw form. Each time one transaction is entered it creates an object with sub class fields, then adds to the account collection. My problem is not understanding how to call the deposit/withdraw method and pass the current transaction amount back to the base class to alculate the new balance. Does anyone have any links to information/tutorials on how to perform something like this? As you can see with my code I have tried various different approaches without any success.
Public Class airplane Private var_num_seats As Integer Private var_num_engines As Integer
[code]....
Obviously, I don't wish that the class Glider has the method "start_engines" neither the property "num_engines". Otherwise, other child classes may have. How can I supress these property and method in child class, not just ignoring (if I can)?
1. In the old VBScript, there was a compareMethod (binary or text, which with text, I could compare case) but I don't find anything like that in the new .Net Replace method. I know I can use the old way, but I'd like to use the new Replace method. I just need a choice of comparing case or not?
2. Let's say I have a long string, and I am using the Replace method - - it would be nice to get the count of instances replaced, and I'm sure that if I read line by line, I could actually get that count, but it would take to long.Is there a way, using the Replace method, to get a count of how many actual replacements were made?
I have nine pictures that I need to animate -I need to use the ToString method and a counter to concatenate a file name into a string variable from the Image.FromFile method. Once the counter reaches its maximum value, and the last picture is displayed, the counter should be reset to zero or one depending on how the first image file has been name. Also a static counter variable should be incremented in the time routine. what I have so far -- I know what I have to do; however, I just do not know how to code this properly.. Right now I have this going thru a button procedure but it needs to go through a timer.