Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

combo box selected value

Posted on 2006-07-21
5
Medium Priority
?
319 Views
Last Modified: 2010-04-23
Hi, there,

I have this code that will get the selected value from the combo and put in the parameter.  The If statement will causes NullRefernceException ("obj ref not set to an instance of an obj") IF I typed a value which matchs one of the listed value, however, when I selected the value by mouse/keystroke, the code works fine. How can I change my if line to accomandate that goal?

            arParms(0) = New SqlParameter("@P1_CSR", SqlDbType.Int)
            If CType(cboCSR.SelectedItem, System.Data.DataRowView).Row("CSR").ToString = "" Then
                arParms(0).Value = DBNull.Value
            Else
                arParms(0).Value = cboCSR.SelectedValue
            End If
And here is how the combo got populated. By the way, the first row of the returned data are Null, Null.

            dsOptions = SqlHelper.ExecuteDataset(cn_str_QWright_Dev, CommandType.StoredProcedure, "CT_getCSR")
            dsOptions.Tables(0).TableName = "CSR"
            cboCSR.DataSource = dsOptions.Tables("CSR")
            cboCSR.DisplayMember = "CSR"
            cboCSR.ValueMember = "EmployeeID"

Thanks in advance!
0
Comment
Question by:ommer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 6

Expert Comment

by:manch
ID: 17158962
In such case u can use the Text property of the combo box or the SelectedIndex property of the compbo box

e.g. ( Replace ur if statement with )

If Trim(cboCSR.Text) = ""  Then
         arParms(0).Value = DBNull.Value
Else
        arParms(0).Value = cboCSR.Text
End If
0
 

Author Comment

by:ommer
ID: 17167863
Manch,

Thank you for your reply.

I need to account for both typing in value and selecting from the list. My original code could handle the selecting from list part.

Using your code to take care of the other half, I run into data type problem..

The parameter has to have a data type of Int. I guest I need a way to loop through my cbo.Items to find the one that eqauls to the typed in value, and make it the selected one.





0
 

Author Comment

by:ommer
ID: 17168151

Here is the one I got it to work. It turned out there is this FindString function I can use. The code block is little too messy than it needs to be.

            If Trim(cboCSR.Text) = "" Then
                If CType(cboCSR.SelectedItem, System.Data.DataRowView).Row("CSR").ToString = "" 
                    arParms(0).Value = DBNull.Value
                Else
                    arParms(0).Value = cboCSR.SelectedValue
                End If
            Else
                cboCSR.SelectedIndex = cboCSR.FindString(cboCSR.Text)
                arParms(0).Value = cboCSR.SelectedValue
            End If
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 17206132
Closed, 125 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question