Null value issue writing to my database

Hi,
I am looking at someone code and need to fix an Null issue. It is really simple but i have not worked in .NET in awhile.
I have a function that takes the values that have been entered into a grid are then written to my sql database.
i need to make sure that if there is a null value, to set it to "" or not null before writing it away
So in belows code snippet, i need to test the PortfolioDescription before getting written tot eh database

thanks allot :)

below is the code
can i use the isDBNull function?

        Dim da As New OdbcDataAdapter
        Dim cmd As New OdbcCommand
        Dim cmd_del As New OdbcCommand
        Dim cmd_ins As New OdbcCommand
        Dim cn As New OdbcConnection
        Dim pr, pr2, pr3 As OdbcParameter

        With cn
            .ConnectionString = CON_STR
            Try
                .Open()
            Catch ex As Exception
                ErrorRoutine(ex)
            End Try
        End With

        With cmd
            .Connection = cn
            .CommandText = " UPDATE ClientGroupPortfolio" & _
                           " SET PortfolioCode=?,PortDescription=?,ExReport=?" & _
                           " WHERE GroupID=? AND PortfolioCode=?"

            '.Parameters.Add("@GroupID", OdbcType.VarChar, 4, "GroupID")
            .Parameters.Add("@PC", OdbcType.VarChar, 6, "PortfolioCode")
            .Parameters.Add("@PDesc", OdbcType.Char, 50, "PortDescription")
            .Parameters.Add("@ExRpt", OdbcType.Bit, 1, "ExReport")

            pr = .Parameters.Add("@GroupID", OdbcType.VarChar, 4, "GroupID")
            pr.SourceVersion = DataRowVersion.Original
            pr2 = .Parameters.Add("@PortfolioCode", OdbcType.VarChar, 6, "PortfolioCode")
            pr2.SourceVersion = DataRowVersion.Original
         
           
        End With

        With cmd_ins
            .Connection = cn
            .CommandText = " INSERT INTO ClientGroupPortfolio" & _
                           " (GroupID,PortfolioCode,PortDescription,ExReport)" & _
                           " VALUES(?,?,?,?)"
            .Parameters.Add("@GroupID", OdbcType.VarChar, 4, "GroupId")

            .Parameters.Add("@PortfolioCode", OdbcType.VarChar, 6, "PortfolioCode")
            .Parameters.Add("@PortDescription", OdbcType.Char, 50, "PortDescription")
            .Parameters.Add("@ExReport", OdbcType.Bit, 1, "ExReport")

        End With


        da.UpdateCommand = cmd
        da.DeleteCommand = cmd_del
        da.InsertCommand = cmd_ins
        Try
            da.Update(dtCGP)
            MessageBox.Show("Updates Completed!", "Client Reporting Group Maintenance", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        Catch ex As Exception
            MessageBox.Show("Update Failed! " & ex.Message, "Client Reporting Group Maintenance", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            'ErrorRoutine(ex)
        End Try

        cn.Close()



LVL 4
CraigLazarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dampseyCommented:
you can use "nothing" to control

if GroupID = nothing then
  groupID = ""
0
CraigLazarAuthor Commented:
hi
forgive my ignorance but i am battling in the code above to figure out where to put ur code. I need to make sure the Productdescription is not NULL
so would i put this statement where?

thanks
0
dampseyCommented:
With cn
            .ConnectionString = CON_STR
            Try
                .Open()
            Catch ex As Exception
                ErrorRoutine(ex)
            End Try
        End With
' put your code here

' put your code here
        With cmd
            .Connection = cn
            .CommandText = " UPDATE ClientGroupPortfolio" & _
                           " SET PortfolioCode=?,PortDescription=?,ExReport=?" & _
                           " WHERE GroupID=? AND PortfolioCode=?"

            '.Parameters.Add("@GroupID", OdbcType.VarChar, 4, "GroupID") ' These words are in '' but I think they should be variables. right????????????? => 'GroupID'
            .Parameters.Add("@PC", OdbcType.VarChar, 6, "PortfolioCode")
            .Parameters.Add("@PDesc", OdbcType.Char, 50, "PortDescription")
            .Parameters.Add("@ExRpt", OdbcType.Bit, 1, "ExReport")

            pr = .Parameters.Add("@GroupID", OdbcType.VarChar, 4, "GroupID")
            pr.SourceVersion = DataRowVersion.Original
            pr2 = .Parameters.Add("@PortfolioCode", OdbcType.VarChar, 6, "PortfolioCode")
            pr2.SourceVersion = DataRowVersion.Original
         
           
        End With
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

CraigLazarAuthor Commented:
well the code was written round a grid, so the values are comming in of a datagrid and not text boxes on a form
which i can see now its datasource is a datatable.
Parameters.Add("@PDesc", OdbcType.Char, 50, "PortDescription")
is the @PDesc holding the actual value?
0
dampseyCommented:
@PDesc is a variable name, the last parameter is/should be the value of the parameter

so if you want gridview value

Parameters.Add("@PDesc", OdbcType.Char, 50, grid1.Rows[0].Cells[0].value.tostring())

or something similar
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CraigLazarAuthor Commented:
ok thanks so much

thats a great help


cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.