|
-
May 2nd, 2013, 01:11 AM
#1
Thread Starter
Junior Member
[RESOLVED] Newbie - Stored procedure fires, table on form not updated?
I'm basically trying to copy a column from one table to another and then display it on a form. Here's what I did -
- Created new Windows application and added a service-based database. ( Visual Basic 2010 Express )
- Added two identical tables to database (Table 1, Table 2) each containing one column named "Component" - Table 1 contains a few rows of data, Table 2 is empty.
- Added a dataset and added both tables to dataset.
( The above instructions I got from a video showing how to add a database to a project, it was all done in the designer using no code )
- Added a button and a DataGridView on the form. Datagrid DataSource = DataSet1, DataMember = Table2.
- Created the following stored procedure - doing a test execute returns no errors -
Code:
ALTER PROCEDURE dbo.StoredProcedure3
AS
INSERT INTO Table2 (Component)
SELECT [Component]
FROM Table1
RETURN
I then added this code into the form ( sample code from net to which I added the currently existing connection string ) -
Code:
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connectionString As String
Dim connection As SqlConnection
Dim adapter As SqlDataAdapter
Dim command As New SqlCommand
Dim ds As New DataSet
connectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=""C:\Users\bob\Documents\Visual Studio 2010\Projects\DatabaseTest1\DatabaseTest1\Database1.mdf"";Integrated Security=True;User Instance=True"
connection = New SqlConnection(connectionString)
connection.Open()
command.Connection = connection
command.CommandType = CommandType.StoredProcedure
command.CommandText = "StoredProcedure3"
adapter = New SqlDataAdapter(command)
adapter.Fill(ds)
connection.Close()
End Sub
End Class
I run the program, click the button, the program doesn't freeze or crash or anything, but nothing shows up on the Datagrid on the form.
My guess is that I did the same thing twice by creating a dataset in the designer and then trying to use a different one in the code.
Thanks to everyone for being so patient with me, this stuff can be awfully confusing when you're first starting out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|