Advertisement

07.23.2008 at 09:01PM PDT, ID: 23590973
[x]
Attachment Details

How to convert an empty string to a null value that can be passed to a stored procedure?

Asked by DanGettel in .NET Framework 2.x, MS SQL Server, Microsoft Visual Basic.Net

I am working on a web form that accesses some of the cells from a gridview on the previous page. One of the cells (First) that I am getting the value from may or may not contain some text.  

I need to pass this text (if there is any) as a variable to my stored procedure, which does a select statement the FormView that appears on the page.

Here is my SqlDataSource select parameters:

                <SelectParameters>
                    <asp:Parameter Name="IDNumber" Type="Int32" />
                    <asp:Parameter Name="First" Type="String" />
                </SelectParameters>

Here is how I am accessing the GridView cells from the previous page for my select parameters:
 
    Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlDataSource1.Selecting
        e.Command.Parameters("@IDNumber").Value = PreviousPage.AppointmentID
        If PreviousPage.First Is Nothing Then
            e.Command.Parameters("@First").Value = System.DBNull.Value
        Else
            e.Command.Parameters("@First").Value = PreviousPage.First
        End If
    End Sub

Here is an example of how I am accessing the GridView cells on the previous page:

Public ReadOnly Property First() As String
Get
Return GridView1.SelectedRow.Cells(4).Text
End Get
End Property

So here is my problem:  The stored procedure works great when I have a value for @First (ie. the cell in the gridview wasn't empty), but when the cell in the gridview is empty I have no value for @First and my stored prcedure doesn't work.  So how can I convert the empty string to a null value that I can pass to my stored procedure?  As you can see from my above code I am trying to account for the possibility of the gridview cell being empty, but so far it is not working.

Thanks for the words of wisdom. Start Free Trial
[+][-]07.23.2008 at 09:40PM PDT, ID: 22076134

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET Framework 2.x, MS SQL Server, Microsoft Visual Basic.Net
Sign Up Now!
Solution Provided By: pratima_mcs
Participating Experts: 3
Solution Grade: A
 
 
[+][-]07.23.2008 at 10:05PM PDT, ID: 22076213

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 02:35AM PDT, ID: 22077329

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 09:10AM PDT, ID: 22080730

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 01:30PM PDT, ID: 22083245

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.24.2008 at 11:59PM PDT, ID: 22086496

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.25.2008 at 06:26AM PDT, ID: 22088303

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.25.2008 at 07:19AM PDT, ID: 22088826

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628