Re: How can I improve this code please?
From: Bob Boran (mcsdsmurf_at_hotmail.com)
Date: 02/24/04
- Next message: abc_at_helloall.com: "Re: Query Help"
- Previous message: Trint Smith: "How can I improve this code please?"
- In reply to: Trint Smith: "How can I improve this code please?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 24 Feb 2004 09:28:23 -0700
Trint,
Based on the error you are getting, this is not an SQL problem. So you
ought to be posting this to the VB.Net board.
However, here are some comments.
1. Where is the problem occuring? is it in the strSQL declare line, or in
the PrepareStr function? I am having a hard time seeing where that error
could come out of any the sample code you are showing.
2. You ought to be using a command object with parameters for the updated
values. This will be more readable, and safer from certain types of SQL
insertion attacks. ( would give you some code for this but it varies
slightly based on the DB you are using. I assume you are using SQL Server,
but nothing in your code verifies this. If you would like a snip, post a
request and I will put it up)
"Trint Smith" <trintsmith@hotmail.com> wrote in message
news:uhb39Dv#DHA.2592@TK2MSFTNGP10.phx.gbl...
> 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(Label6.Text) & _
> " ,item_itemcurrentbidprice = " &
> PrepareStr(itemCurrentbidprice) & _
> " ,item_itembidhistory = " &
> PrepareStr(itembidHistory) & _
> " ,item_itemcurrentorpurchasedbidder = " &
> PrepareStr(itemCurrentorpurchasedbidder) & _
> "FROM TBL_Items " & _
> "WHERE item_itemnumber = '" & Label6.Text & "'"
>
> Here is the code:
>
> Private Function PrepareStr(ByVal 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
>
>
> Net programmer
> trintsmith@hotmail.com
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
- Next message: abc_at_helloall.com: "Re: Query Help"
- Previous message: Trint Smith: "How can I improve this code please?"
- In reply to: Trint Smith: "How can I improve this code please?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|