Note that there are some explanatory texts on larger screens.

plurals
  1. PORazor VB - Pass a Null value if a Request variable is empty
    primarykey
    data
    text
    <p>I've been trying so hard to find a solution for this, but no luck. I'm fairly new to VB and SQL, but this shouldn't be too hard. I've inherited a lot of code and there's not too much room to change db attribute types or anything.</p> <p>I'm trying to run an UPDATE query using parameters in Razor, like so:</p> <pre><code> Dim updateCommand = "UPDATE [tblJobRating] SET [ProjectManagement] = @0, [ProjComments] = @1, [Schedule] = @2, [SchedComments] = @3 WHERE [JobRatingID] = @4" </code></pre> <p>All of the columns in question need INT values, but I have one exception where I need to pass it a null value (passing another number or zero won't do). Essentially a "N/A" value for the user.</p> <p>I assign the variables from Post requests, like so:</p> <pre><code>Dim projMgmt = Request.Form('projMgmt') ' ... Dim sched = Request.Form('sched') </code></pre> <p>I have the "N/A" value posting no value right now (or it can be a string and I can check for IsNumber if need be, I guess). But when I call the query execution, it enters the value as a 0.</p> <pre><code>db.Execute(updateCommand, projMgmt, projComments, sched, schedComments, ratingId) </code></pre> <p>It needs to be a NULL value for the backend to work properly. I've tried type checking and passing <code>Nothing</code>, <code>System.Data.SqlTypes.SqlInt32.Null</code>, etc., but it either gives conversion errors or sets to 0. How can I pass it properly?</p> <p><strong>Edit:</strong> I left out the first param in the db.Execute method, passing in the updateCommand. Edited for clarity.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload