473,786 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I improve this code please?

How can I improve this code please?
It sometimes produces this error:
"Object reference not set to an instance of an object"
When I do this:
strSQL = "UPDATE TBL_Items SET" & _
" item_itemnumber = " & PrepareStr(Labe l6.Text) & _
" ,item_itemcurre ntbidprice = " &
PrepareStr(item Currentbidprice ) & _
" ,item_itembidhi story = " &
PrepareStr(item bidHistory) & _
" ,item_itemcurre ntorpurchasedbi dder = " &
PrepareStr(item Currentorpurcha sedbidder) & _
"FROM TBL_Items " & _
"WHERE item_itemnumber = '" & Label6.Text & "'"

Here is the code:

Private Function PrepareStr(ByVa l strValue As String) As String
' This function accepts a string and creates a string that can
' be used in a SQL statement by adding single quotes around
' it and handling empty values.
If strValue.Trim() = "" Then
Return "NULL"
Else
Return "'" & strValue.Trim() & "'"
End If
End Function

Thanks,
Trint
.Net programmer
tr********@hotm ail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
4 1170
It looks like your function will return the word NULL to your calling
function, when what it looks like you want to return is 'NULL'. Another
idea is to return String.Empty instead of "NULL".

Stephajn
"Trint Smith" <tr********@hot mail.com> wrote in message
news:u8******** **********@TK2M SFTNGP10.phx.gb l...
How can I improve this code please?
It sometimes produces this error:
"Object reference not set to an instance of an object"
When I do this:
strSQL = "UPDATE TBL_Items SET" & _
" item_itemnumber = " & PrepareStr(Labe l6.Text) & _
" ,item_itemcurre ntbidprice = " &
PrepareStr(item Currentbidprice ) & _
" ,item_itembidhi story = " &
PrepareStr(item bidHistory) & _
" ,item_itemcurre ntorpurchasedbi dder = " &
PrepareStr(item Currentorpurcha sedbidder) & _
"FROM TBL_Items " & _
"WHERE item_itemnumber = '" & Label6.Text & "'"

Here is the code:

Private Function PrepareStr(ByVa l strValue As String) As String
' This function accepts a string and creates a string that can
' be used in a SQL statement by adding single quotes around
' it and handling empty values.
If strValue.Trim() = "" Then
Return "NULL"
Else
Return "'" & strValue.Trim() & "'"
End If
End Function

Thanks,
Trint
Net programmer
tr********@hotm ail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #2
* Trint Smith <tr********@hot mail.com> scripsit:
How can I improve this code please?
It sometimes produces this error:
"Object reference not set to an instance of an object"


On which line?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet/>

..NET FAQs: <http://www.mvps.org/dotnet/dotnet/faqs/> (German)
Nov 20 '05 #3
Cor
Hi Trint,

Have a look at command.paramet ers that is made for this.

http://msdn.microsoft.com/library/de...eterstopic.asp

I hope this helps,

Cor
How can I improve this code please?
It sometimes produces this error:
"Object reference not set to an instance of an object"
When I do this:
strSQL = "UPDATE TBL_Items SET" & _
" item_itemnumber = " & PrepareStr(Labe l6.Text) & _
" ,item_itemcurre ntbidprice = " &
PrepareStr(item Currentbidprice ) & _
" ,item_itembidhi story = " &
PrepareStr(item bidHistory) & _
" ,item_itemcurre ntorpurchasedbi dder = " &
PrepareStr(item Currentorpurcha sedbidder) & _
"FROM TBL_Items " & _
"WHERE item_itemnumber = '" & Label6.Text & "'"

Here is the code:

Private Function PrepareStr(ByVa l strValue As String) As String
' This function accepts a string and creates a string that can
' be used in a SQL statement by adding single quotes around
' it and handling empty values.
If strValue.Trim() = "" Then
Return "NULL"
Else
Return "'" & strValue.Trim() & "'"
End If
End Function

Nov 20 '05 #4
thanks Cor.
Herfried:
If strValue.Trim() = "" Then
Return "NULL"


Thanks,
Trint

.Net programmer
tr********@hotm ail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2075
by: | last post by:
I am trying to improve the robustness and elegance of my parametized sql statements in ASP 3.0 as they get passed to the sql server SP. Could anyone tell me if there are weaknessess in the way I have written the following code? I have included both the asp code and the sql stored proceducre to tie things togoether....I appreciate any advice on this. It basically is a application to manage static news stories on our site by tracking and...
7
10817
by: Bing Wu | last post by:
Hi Folks, I have a very large table containing 170 million rows of coordinats: CREATE TABLE "DB2ADMIN"."COORDINATE" ( "FID" INTEGER NOT NULL , "AID" INTEGER NOT NULL , "X" REAL NOT NULL , "Y" REAL NOT NULL , "Z" REAL NOT NULL )
9
4618
by: Peng Jian | last post by:
I have a function that is called very very often. Can I improve its efficiency by declaring its local variables to be static?
9
1584
by: goosen_cug | last post by:
This program is a "Sequential List" class I want to do the Union Operation,Intersection Operation of the Set.But this program have a problem: /////////////////////////// Compiling... Set.cpp H:\cheung\Set\Set.cpp(81) : error C2664: 'Insert' : cannot convert parameter 1 from 'int' to 'int &' A reference that is not to 'const' cannot be bound to a non-lvalue
16
3078
by: weidongtom | last post by:
Hi, I have just finished reading some tutorials on C, I am wondering how I could improve my skill. Is there any advice? Is reading others' codes the best way? If so, what type of codes are suitable for novice? The ones in fsf freed software directory? I have been reading quite a few books on the programming language C, but when I tried to start a project of my own, I find myself to be incompetent. What should I do? Thanks in advance.
11
3387
by: Peted | last post by:
Im using c# 2005 express edition Ive pretty much finished an winforms application and i need to significantly improve the visual appeal of the interface. Im totaly stuck on this and cant seem to work out how to start on a solution. I have of course used a varienty of componets, mostly radio buttons with "button" appearence.
8
1455
by: tony | last post by:
Hi, now I've known the basics about C++. What I can do is pretty limited. I've known something in Java: 1.Networking(Socket, RMI, Servlet) 2.Database(JDBC) 3.GUI (Java Swing) 4.and some others APIs... I'm wondering how can I do all of the above in C++. And I've heard that reading source codes can help one improve its programming skills, but I don't know how to
2
2775
by: sdanda | last post by:
Hi , Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity ......... This has to work for more than 8,00,000 of records ..... Can you give some performance tips if you have known 1) For this I am using oci driver ( because I m using oracle 10g) instead of thin driver 2) In that programme I m using prepared statement instead of statement 3) I am...
3
3643
by: oravm | last post by:
Hi, I re-write a query and used bulk collect to improve the performance of the batch process. The query below has NO compile error but when execute query there is error 'ORA-01403: no data found.' CREATE OR REPLACE PROCEDURE PROCESS_ANGKASA(REF_NO varchar2)is v_cntr_code varchar2(16); v_receipt_code varchar2(3); start_time number; end_time number;
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10169
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.