Skip to main content
fixed tags and title
Link
Malachi
  • 29.1k
  • 11
  • 87
  • 188

Calling stored procedure with a sql commandsqlCommand

Calling stored procedure with `sqlCommand`a sql command

I have the following code as part of an sqlcommandsqlCommand which is calling a stored procedure:

Dim groupObj

If groupId = 0 Then
    groupObj = DBNull.Value
Else
    groupObj = groupId
End If

Dim siteObj

If siteId = 0 Then
    siteObj = DBNull.Value
Else
    siteObj = siteId
End If

sqlCommand.Parameters.Add(New SqlClient.SqlParameter("GroupID", SqlDbType.Decimal)).Value = groupObj
sqlCommand.Parameters.Add(New SqlClient.SqlParameter("SiteID", SqlDbType.Decimal)).Value = siteObj

I basically want to check for a condition and (if true) send a DBNull instead. This code looks awful however - is there a way to succinct this up?

Calling stored procedure with `sqlCommand`

I have the following code as part of an sqlcommand which is calling a stored procedure:

Dim groupObj

If groupId = 0 Then
    groupObj = DBNull.Value
Else
    groupObj = groupId
End If

Dim siteObj

If siteId = 0 Then
    siteObj = DBNull.Value
Else
    siteObj = siteId
End If

sqlCommand.Parameters.Add(New SqlClient.SqlParameter("GroupID", SqlDbType.Decimal)).Value = groupObj
sqlCommand.Parameters.Add(New SqlClient.SqlParameter("SiteID", SqlDbType.Decimal)).Value = siteObj

I basically want to check for a condition and (if true) send a DBNull instead. This code looks awful however - is there a way to succinct this up?

Calling stored procedure with a sql command

I have the following code as part of an sqlCommand which is calling a stored procedure:

Dim groupObj

If groupId = 0 Then
    groupObj = DBNull.Value
Else
    groupObj = groupId
End If

Dim siteObj

If siteId = 0 Then
    siteObj = DBNull.Value
Else
    siteObj = siteId
End If

sqlCommand.Parameters.Add(New SqlClient.SqlParameter("GroupID", SqlDbType.Decimal)).Value = groupObj
sqlCommand.Parameters.Add(New SqlClient.SqlParameter("SiteID", SqlDbType.Decimal)).Value = siteObj

I basically want to check for a condition and (if true) send a DBNull instead. This code looks awful however - is there a way to succinct this up?

Tweeted twitter.com/#!/StackCodeReview/status/134953767954153472

I have the following code as part of an sqlcommandsqlcommand which is calling a stored procedure:

            Dim groupObj

            If groupId = 0 Then
                groupObj = DBNull.Value
            Else
                groupObj = groupId
            End If

            Dim siteObj

            If siteId = 0 Then
                siteObj = DBNull.Value
            Else
                siteObj = siteId
            End If

            sqlCommand.Parameters.Add(New SqlClient.SqlParameter("GroupID", SqlDbType.Decimal)).Value = groupObj
            sqlCommand.Parameters.Add(New SqlClient.SqlParameter("SiteID", SqlDbType.Decimal)).Value = siteObj

I basically want to check for a condition and (if truetrue) send a DBNullDBNull instead. This code looks awful however - is there a way to succinct this up?

I have the following code as part of an sqlcommand which is calling a stored procedure:

            Dim groupObj

            If groupId = 0 Then
                groupObj = DBNull.Value
            Else
                groupObj = groupId
            End If

            Dim siteObj

            If siteId = 0 Then
                siteObj = DBNull.Value
            Else
                siteObj = siteId
            End If

            sqlCommand.Parameters.Add(New SqlClient.SqlParameter("GroupID", SqlDbType.Decimal)).Value = groupObj
            sqlCommand.Parameters.Add(New SqlClient.SqlParameter("SiteID", SqlDbType.Decimal)).Value = siteObj

I basically want to check for a condition and (if true) send a DBNull instead. This code looks awful however - is there a way to succinct this up?

I have the following code as part of an sqlcommand which is calling a stored procedure:

Dim groupObj

If groupId = 0 Then
    groupObj = DBNull.Value
Else
    groupObj = groupId
End If

Dim siteObj

If siteId = 0 Then
    siteObj = DBNull.Value
Else
    siteObj = siteId
End If

sqlCommand.Parameters.Add(New SqlClient.SqlParameter("GroupID", SqlDbType.Decimal)).Value = groupObj
sqlCommand.Parameters.Add(New SqlClient.SqlParameter("SiteID", SqlDbType.Decimal)).Value = siteObj

I basically want to check for a condition and (if true) send a DBNull instead. This code looks awful however - is there a way to succinct this up?

Source Link
m.edmondson
  • 327
  • 1
  • 2
  • 9
Loading