Solved

Urgent! VB.NET -- Need to execute a TableAdapter query using a DataGridView column value!

Posted on 2013-01-11
2
1,023 Views
Last Modified: 2013-01-12
Hi everyone,

I have a TableAdapter which is filled with multiple queries.

I want to use a DataGridViewCell value as a parameter in a TableAdapter query

My current code throws an exception because the DataGridViewCell value is returning as dbNull even though it has a value.

Here is the current code which is taken from a Form KeyUp event:

Select Case e.KeyCode
            Case Keys.F8
                Dim columnValue As String = DataGridView1.Currentcell.Value.ToString()

                        Try
                            ' Me.Table1TableAdapter.FillByQuery1(Me.Dataset1.Table1, columnvalue)
                        Catch ex As Exception
                            MessageBox.Show(ex.Message)
                        End Try


        End Select

Thanks for your help!
0
Comment
Question by:eq2006
2 Comments
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
ID: 38769815
Put following at the beginning

DataGridView1.EndEdit()
0
 
LVL 9

Accepted Solution

by:
sognoct earned 250 total points
ID: 38769864
Case Keys.F8
                DataGridView1.EndEdit()
                Me.Dataset1.Table1.acceptchanges()

                Dim columnValue As String = DataGridView1.Currentcell.Value.ToString()

                        Try
                            ' Me.Table1TableAdapter.FillByQuery1(Me.Dataset1.Table1, columnvalue)
                        Catch ex As Exception
                            MessageBox.Show(ex.Message)
                        End Try


        End Select
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now