473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

HELP!!! For the life of me I can't figure out how to get my datagrid to update!

I've got a database that I've been working on for over a year and a half but I've just recently finished the back end to the point of feeling comfortable with starting on a front end.

So while I've been able to pick up a great deal just stumbling through on my own with the several apress books I've gotten a hold of I've figured out a great deal and have some half decent forms for data entry but for the life of me I can't figure out how to get the databinding to do whatever it does again after having entered data into the database.

My problem placed more concisely

My form's data grid populates from a stored procedure via a binding source.

My form's button then uses another stored procedure to enter in the data into the database.

What I want to do is have the datagrid recall the stored procedure and refresh the grid with the newly modified data included.

This is what I've been racking my brain over for some time, and scouring the internet and my various apress books for, is figuiring out why none of my attempts at doing this are working.

I'm just finding most all of the stuff out there about datagrids and the such are not at all tailored towards a person trying to do all their interactions via stored procedures. I know I can do the basics, and the forms work and I know that if I just close the form and access it manually again that the datagrid reloads with the newly input data, but I'm really trying to get it so that I'm making a UI that is as easy to use as I can get it.


I'd appreciate it if you, or anyone, could point out what I'm doing wrong, or not doing right, or both.

Sorry the code is so weird here. I accidentally posted this question in the old vb land.

Here's a link if you want a prettier view of the code--

http://bytes.com/topic/visual-basic/answers/879935-how-get-datagrid-uses-stored-procedure-initially-populate-refresh#post3540295

Expand|Select|Wrap|Line Numbers

1. ===========
2.
3. Imports System
4. Imports System.Data
5. Imports System.Data.SqlClient
6.
7.
8. Public Class WholeAppleInsertion
9.
10. ' This form is for entering Apple Names with their corresponding
11. ' Type. I'm presently trying to get it to work where after submitting
12. ' the new name that the data grid will reset itself via calling upon the
13. ' stored procedure originally used to populate the grid so that it can
14. ' repopulate it, giving an updated view to the user
15.
16.
17.
18. Private Sub WholeAppleInsertion_Load( _
19. ByVal sender As System.Object, _
20. ByVal e As System.EventArgs) _
21. Handles MyBase.Load
22. 'TODO: This line of code loads data into the 'VaedaAlefDataSet1.spSelectallWholeApple' _
23. ' table. You can move, or remove it, as needed.
24. Me.spSelectallWholeAppleTableAdapter1.Fill(Me.Vaed aAlefDataSet1.spSelectallWholeApple)
25.
26. Me.spSelectAppleTypeTableAdapter.Fill(Me.VaedaAlef DataSet.spSelectAppleTypeTableAdapterType)
27.
28. Me.spSelectallWholeAppleTableAdapter.Fill( _
29. Me.VaedaAlefDataSet.spSelectallWholeApple)
30.
31. End Sub
32.
33.
34.
35. ' This is the data grid that holds the list of Apple names with their types
36. ' that are found in the database. THIS is the data grid that I want to get to
37. ' update, to refresh, or however you'd say it, whenever the button is pushed.
38.
39. Private Sub DataGridView1_CellContentClick( _
40. ByVal sender As System.Object, _
41. ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
42. Handles DataGridView1.CellContentClick
43.
44. End Sub
45.
46.
47.
48. '########THIS IS THE BUTTON CLICK EVENT I WANT TO
49. '########TRIGGER THE REFRESHING OF THE DATAGRID
50.
51. Public Function EnterApple_Click( _
52. ByVal sender As System.Object, _
53. ByVal e As System.EventArgs) As SqlDataReader _
54. Handles EnterApple.Click
55.
56.
57. Using sqlconn As New SqlConnection
58. Dim retval As Integer
59.
60. sqlconn.ConnectionString = "Data Source=SQUASHERZ-PC\SQLEXPRESS;Initial Catalog=VaedaAlef;Integrated Security=True"
61. sqlconn.Open()
62.
63. Dim sqlComm As New SqlCommand
64. sqlComm.Connection = sqlconn
65. sqlComm.CommandType = CommandType.StoredProcedure
66. sqlComm.CommandText = "spInserlectWholeApple"
67.
68. Try
69. sqlComm.Parameters.Add("@Name", SqlDbType.VarChar)
70. sqlComm.Parameters.Add("@Type", SqlDbType.SmallInt)
71. sqlComm.Parameters("@Name").Direction = ParameterDirection.Input
72. sqlComm.Parameters("@Name").Value = TxtAppleName.Text
73. sqlComm.Parameters("@Type").Direction = ParameterDirection.Input
74. sqlComm.Parameters("@Type").Value = ParameterDirection.Input = ComboBox1.SelectedValue
75.
76. retval = sqlComm.ExecuteNonQuery()
77. Catch Sqlex As SqlException
78. MessageBox.Show(Sqlex.Message)
79. End Try
80.
81.
82. TxtAppleName.Text = ""
83.
84.
85. If retval >= 1 Then
86. MsgBox("something happened")
87.
88.
89. End If
90.
91.
92. ' //Here below are my attempts at getting this to refresh
93. ' //It likely makes it clear that I don't know what I'm doing
94. ' PLEASE HELP!
95.
96. Me.WholeAppleInsertion_ResetBindings()
97.
98. Me.spSelectallWholeAppleBindingSource1.ResetItem(0 )
99.
100. Me.DataGridView1.Refresh()
101.
102. sqlconn.Close()
103.
104. End Using
105.
106.
107. End Function
108.
109.
110.
111. Private Sub TextBox1_TextChanged( _
112. ByVal sender As System.Object, _
113. ByVal e As System.EventArgs) _
114. Handles TxtAppleName.TextChanged
115.
116. End Sub
117.
118. Private Sub ComboBox1_SelectedIndexChanged( _
119. ByVal sender As System.Object, _
120. ByVal e As System.EventArgs)
121.
122.
123. End Sub
124.
125. Private Sub ComboBox1_SelectedIndexChanged_1( _
126. ByVal sender As System.Object, _
127. ByVal e As System.EventArgs) _
128. Handles ComboBox1.SelectedIndexChanged
129.
130. End Sub
131.
132.
133. Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, _
134. ByVal e As System.ComponentModel.DoWorkEventArgs) _
135. Handles BackgroundWorker1.DoWork
136.
137. End Sub
138.
139. Private Sub spSelectallWholeAppleBindingSource1_CurrentChanged _
140. (ByVal sender As System.Object, _
141. ByVal e As System.EventArgs) _
142. Handles spSelectallWholeAppleBindingSource1.CurrentChanged
143.
144. End Sub
145. 'This sub is the binding source that retrieves the data for the data grid
146. 'This is what I'm trying to figure out how to get it to refresh so that the data
147. 'grid displays the new information whenever a new name is submitted via the 'submit
148. 'new button' button.
149. Private Sub spSelectallWholeAppleBindingSource_CurrentChanged _
150. (ByVal sender As System.Object, _
151. ByVal e As System.EventArgs) _
152. Handles spSelectallWholeAppleBindingSource.CurrentChanged
153.
154.
155. End Sub
156.
157.
158. End Class
159.
160. #################################

I'm using Visual Studio 08 and I've been leaning on the GUI so if there are code elements that don't make sense please let me know. I'm trying to learn this as fast as I can, I'm just not learning how to fix this particular item fast enough.
Jan 22 '10 #1
0 1076

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Bill Salling | last post by:
am trying to updated the source data(Access2000) for my data grid. But keep getting this error An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dl ...
2
by: Randy | last post by:
Hello All, I'm trying to discover the best way to handle the situation where you have a datagrid in your app and someone changes a cell but doesn't leave that cell (so there's the little pencil...
13
by: abdoly | last post by:
i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being update that is the code private void DataGrid1_UpdateCommand(object source,...
3
by: pmud | last post by:
Hi, I have an ASP.NET application using C# code. I am using a datagrid to display records from a database based on a user input, i.e a user enters a compnay name in text box & when he clicks a...
1
by: siaj | last post by:
Helo All, If some one has faced a similar issue.. My datagrid Update command is not getting fired in fact it seems that the no event fires on clicking the update link. Although the cancel and the...
4
by: siaj | last post by:
Hello All, If some one has faced a similar issue.. My datagrid Update command is not getting fired in fact it seems that the no event fires on clicking the update link. Although the cancel and the...
3
by: Eveready | last post by:
Hi, I would like to have datagrid update all rows by clicking one button. I need to know how to cycle through each row and get the value in the 3rd column. Any help is appreciated. thnx...
3
by: Kentor | last post by:
hello, im trying to make a little loop, but i cant figure it out... i have a string with a bunch of 1s and 0s in it: 110101010101111010101 .... i need to count the number of 1s divide it by 2 and...
4
by: Suyash Upadhyay | last post by:
Hello all, I have studied that while we apply UNIQUE constraint any column have maximum one field as NULL, but in my code there are two NULL values, Please help me to figure it out. ...
5
by: chevon1920 | last post by:
I am trying to do my assignment but I cant figure out how to get 8 data points per line to print to a file. Here is the assignment 1. Program asks the user to enter an odd number as a BASE,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.