Hi,
As a learning exercise I have created a simple form which contains a
DataGridView, a Textbox and a Command Button. The DGW is populated from a
stored procedure which optionally takes a parameter to filter the data
retrieved.
When the form is first loaded, the DGV is populated from the procedure with
no parameter - I've managed to get this bit working fine.
What I'd like to happen next is for the user to enter a reference ("visit")
in the text box and when the user clicks the command button, the data in the
DGV is refreshed as per the procedure executing with the parameter.
However, I'm unable to do this, I just can't get the data to refresh. I'm
not sure at what stage I should be refreshing the data and who I achieve
it...
My form consists of a single DGV, one textbox and one command button. I
haven't included any error handling or such like.
I'd be much appreciative if someone could give me a few pointers as to how
to get the form to refresh as described above.
I hope I've managed to explain this clearly enough!
Many thanks
Chris.
**************************
Public Class Form1
Dim cnn As New SqlClient.SqlConnection( _
"Data Source=COMPUTER19\CSTEST;" & _
"Initial Catalog=ShipsPerf_Test;" & _
"Integrated Security=True")
Dim bs As New BindingSource()
Dim cmd As New SqlClient.SqlCommand()
Dim prm As New SqlClient.SqlParameter
Dim da As New SqlClient.SqlDataAdapter()
Dim data As New DataSet()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cmd.Connection = cnn
cmd.CommandText = "spGangsInvolvedWithVisitSelect"
cmd.CommandType = CommandType.StoredProcedure
da.SelectCommand = cmd
da.Fill(Data, "Visits")
bs.DataSource = Data
bs.DataMember = "Visits"
Me.DataGridView1.DataSource = bs
With Me.DataGridView1
.AutoResizeColumns()
.AutoResizeRows()
End With
End Sub
Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdRefresh.Click
cmd.Connection = cnn
cmd.CommandText = "spGangsInvolvedWithVisitSelect"
cmd.CommandType = CommandType.StoredProcedure
prm = cmd.Parameters.Add("@Visit", SqlDbType.Int)
prm.Value = Me.txtVisit.Text
da.SelectCommand = cmd
bs.DataSource = data
bs.DataMember = "Visits"
Me.DataGridView1.DataSource = bs
Me.DataGridView1.Refresh()
End Sub
End Class 2 5697
Chris,
In the cmdRefresh click procedure you change the cmd for the
dataadapter. You forgot to clear the dataset and call the dataadapters fill
method again to get the data you are looking for.
Here is a link to an example. http://www.vb-tips.com/default.aspx?...f-ba7a1d82b540
Ken
------------------
"Chris Strug" wrote: Hi,
As a learning exercise I have created a simple form which contains a DataGridView, a Textbox and a Command Button. The DGW is populated from a stored procedure which optionally takes a parameter to filter the data retrieved.
When the form is first loaded, the DGV is populated from the procedure with no parameter - I've managed to get this bit working fine.
What I'd like to happen next is for the user to enter a reference ("visit") in the text box and when the user clicks the command button, the data in the DGV is refreshed as per the procedure executing with the parameter.
However, I'm unable to do this, I just can't get the data to refresh. I'm not sure at what stage I should be refreshing the data and who I achieve it...
My form consists of a single DGV, one textbox and one command button. I haven't included any error handling or such like.
I'd be much appreciative if someone could give me a few pointers as to how to get the form to refresh as described above.
I hope I've managed to explain this clearly enough!
Many thanks
Chris.
************************** Public Class Form1
Dim cnn As New SqlClient.SqlConnection( _ "Data Source=COMPUTER19\CSTEST;" & _ "Initial Catalog=ShipsPerf_Test;" & _ "Integrated Security=True") Dim bs As New BindingSource() Dim cmd As New SqlClient.SqlCommand() Dim prm As New SqlClient.SqlParameter Dim da As New SqlClient.SqlDataAdapter() Dim data As New DataSet()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cmd.Connection = cnn cmd.CommandText = "spGangsInvolvedWithVisitSelect" cmd.CommandType = CommandType.StoredProcedure
da.SelectCommand = cmd da.Fill(Data, "Visits")
bs.DataSource = Data bs.DataMember = "Visits"
Me.DataGridView1.DataSource = bs
With Me.DataGridView1 .AutoResizeColumns() .AutoResizeRows() End With End Sub
Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click cmd.Connection = cnn cmd.CommandText = "spGangsInvolvedWithVisitSelect" cmd.CommandType = CommandType.StoredProcedure
prm = cmd.Parameters.Add("@Visit", SqlDbType.Int) prm.Value = Me.txtVisit.Text
da.SelectCommand = cmd
bs.DataSource = data bs.DataMember = "Visits"
Me.DataGridView1.DataSource = bs Me.DataGridView1.Refresh() End Sub End Class
"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com... Chris,
In the cmdRefresh click procedure you change the cmd for the dataadapter. You forgot to clear the dataset and call the dataadapters fill method again to get the data you are looking for.
Here is a link to an example. http://www.vb-tips.com/default.aspx?...f-ba7a1d82b540
Ken ------------------
"Chris Strug" wrote:
Ken,
Many thanks for your reply - that's certainly cleared things up!
Thanks again
Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: MS |
last post by:
Access 97
I want to requery the data being displayed on a form, then I want to return
to the record I was in.
Why doesn't this code work?
Private Sub CmdRefsh_Click()
|
by: Max |
last post by:
How do you for the datagridview control to requery the database??
Thanks,
--max
|
by: reidarT |
last post by:
I have some fields with a button that adds records to an Access db.
The fields get values from the fieleds.
In the same window I have a datagrid with a list of the same records from
the access db....
|
by: MJ |
last post by:
Newbie question.
I have a DataGridView which is bound to a manually created read only
DataSet. One of the fields in the dataset is a primary key of the table. I
simply wish to know which record...
|
by: Mitchell S. Honnert |
last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?
Here's...
| |
by: mrowe |
last post by:
I am using Access 2003. (I am also using ADO in the vast majority of my code. I recently read a post that indicated that ADO is not all that is was initially cracked up to be. In the back of my...
|
by: jeastman - Hotmail |
last post by:
Hello world
Excuse, not to be written English and it helps me with a translator.
I am new programming in C#.
I made a control inheriting the DataGridView to be able to add controls done
by...
|
by: =?ISO-8859-1?Q?Andrea_M=FCller?= |
last post by:
Hello,
I have one problem.
Include my project is a dataset with tables.
During my process I create a new temporary table.
The dataset use my DataGrid Control.
The use delete now one, two...
|
by: Andrus |
last post by:
I have DataGridView in virtual mode containing 3500 rows.
In code below, assigning to RowCount value to 3500 takes 8 seconds.
CPU usage goes high at this time.
Stepping by F11 into user code shows...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |