Avatar of David_Graves
 asked on

Filterexpression and NULL

Dim drPromptOverride() As DataRow = Me.PDICompany_780_02DataSet.SAPPBROS_780_Card_Prompt_Overrides.Select(String.Concat("Cust_Key = ", Convert.ToInt32(dgvCustSelect.CurrentRow.Cells("Cust_Key").Value), " AND Card_Key IS NULL "))

Open in new window

The SQL database this is built for does indeed have a row that matches the criteria (where Card_Key is a null value), but the .select is returning 0 rows.

I am guessing I have the NULL portion of the expression string coded incorrectly. Any ideas?
Visual Basic.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon
Nasir Razzaq

Add a messagebox to see what the filter expression is evaluating to.

The filter expression is not stored with drPromptOverride, so I am unsure how to see what it is.
Nasir Razzaq

You can add the following line just above the line you have

Msgbox String.Concat("Cust_Key = ", Convert.ToInt32(dgvCustSelect.CurrentRow.Cells("Cust_Key").Value), " AND Card_Key IS NULL ")
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes

Hmmm... it seems to be working now.

I think what happened is I added the row I was looking for, but didn't update the dataset adapter so it wasn't finding it.

Although I had used the TableAdapter.Insert method to create the row in the first place, I thought that the data adapter would have been automatically updated.
Nasir Razzaq

No it requires that you call the Update method to propagate changes back to DB.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

The TableAdapter.Insert method is inserting the row into the database. Why would I need to use the Update method?

It seems to me that after I to the Insert method, I need to re-select the data, but that seems counter-intuitive to using a DataAdapter in the first place.

Now I am confused.

In other words:

        Dim fEx As String = String.Concat("Cust_Key = ", Convert.ToInt32(dgvCustSelect.CurrentRow.Cells("Cust_Key").Value), " AND Card_Key IS NULL")
        Dim drPromptOverride() As DataRow = Me.PDICompany_780_02DataSet.SAPPBROS_780_Card_Prompt_Overrides.Select(fEx)

            If drPromptOverride.Count = 0 Then
                Me.SappbroS_780_Card_Prompt_OverridesTableAdapter1.Insert(Convert.ToInt32(dgvCustSelect.CurrentRow.Cells("Cust_Key").Value), _
                                                                          nullDecimal, _
                                                                          Convert.ToInt16(Me.CP_Plate.CheckState), _
                                                                          Convert.ToInt16(Me.CP_Truck.CheckState), _
                                                                          Convert.ToInt16(Me.CP_Mileage.CheckState), _
                                                                          Convert.ToInt16(Me.CP_DriverID.CheckState), _
                                                                          Convert.ToInt16(Me.CP_Trip.CheckState), _
                                                                          Convert.ToInt16(Me.CP_PO.CheckState), _

Open in new window

works and adds the row to the table when it did not find it the first time. When I attempt again, it does not find the row in drPromptOverride and attempts the insert a second time (and of course, if I restart the project, it works as intended)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck