473,563 Members | 2,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get a DataGrid that uses a Stored Procedure to initially populate to refresh

5 New Member
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.
Jan 16 '10 #1
3 2816
vb5prgrmr
305 Recognized Expert Contributor
First, try the .Refresh/.Requery of the data source to see if the grid is updated correctly with the new information. That is if the binding source as you call it is not used for the insert stored procedure. If it is, then you need to close and rebind the data source to execute the query stored procedure.



Good Luck
Jan 16 '10 #2
FrustratedNoob
5 New Member
I have posted my code with any sensitive info uniformly modififed. I'd appreciate it if you, or anyone, could point out what I'm doing wrong, or not doing right, or both.

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.VaedaAlefDataSet1.spSelectallWholeApple)
  25.  
  26.         Me.spSelectAppleTypeTableAdapter.Fill(Me.VaedaAlefDataSet.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 20 '10 #3
vb5prgrmr
305 Recognized Expert Contributor
Well now that I see that you are NOT using Visual Basic 6.0 BUT are using VB.NET! I would suggest that you look to the right of your original post.... now do you see where it says vb.net???? That would be the place for your question...



Good Luck
Jan 21 '10 #4

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

Similar topics

11
5214
by: harborboy76 | last post by:
Hi, I have a stored procedure that does a lot of INSERT/UDATE to 3 tables. And When I call the stored procedure, I get a Transaction Log Full error. When I want to do is turning off the transaction log on those 3 tables that the stored procedure is using. Now, since I call the stored procedure on the command line (CLI), where do I run ALTER...
1
1758
by: BigD | last post by:
This all centers around an Access Data Project I have a stored procedure that aggregates events stored in a table based on intervals I specify. I have a form that supplies parameters for the stored procedure. My procedure creates a temp table to populate with the results. The problem I have is that I cannot create a form or report that uses...
2
3957
by: Not Me | last post by:
Hey, Coming back to a piece of work I did a while back, which used a stored procedure to populate a list box. The SP takes a single parameter, and I think this is the reasoning for using 'exec' in the row source (I assume you need this for parameters?) The problem is this only works when I access the form.. If I do it from someone...
2
5442
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
2
2235
by: Max | last post by:
Is it possible or more effecient to use a stored procedure to populate a datagrid when using datagrid or custom paging? Is it (ADO.NET?) pulling the entire table into the dataset or is it just pulling the page as defined by the page size? I'm assuming that if I use a stored procedure with a datagrid, I won't be able to use the datagrid's...
10
13283
by: Rich | last post by:
I have a stored procedure on Sql Server2k. I can fill a data table which I can append to a dataset using an ADODB recordset object which gets populated from a command object that runs the sp. I was hoping to use a DataAdapter. But I think the data adapter only uses select statements. I could write the sp in my vb.net app, but the sp...
9
2451
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug through the application in Visual Studio .NET 2003 the application an exception when it executes the query.
1
4172
by: Orit | last post by:
Hi . I am creating an ASP.NET 2.0 web site and have the following problem : 1. I have a GridView which bound to the object data source. 2. This object data source is SQL Table adapter that I added to the data set via IDE . 3. The method GetData of this table adapter uses existing stored procedure on my SQL 2005 server. 4. Everything...
11
3399
by: peter | last post by:
I am trying to get a SQL stored procedure to use user maintained MQT implicitly which raises questions on when they are used or not used. In theory you would expect the stored procedure to pick up the MQT at the time it is bound on the creation of the static SQL. This raises the question on how you stop it or start it using a MQT as there is...
3
4467
by: FrustratedNoob | last post by:
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...
0
7664
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7948
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.