473,385 Members | 1,766 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,385 software developers and data experts.

Stored procedure help for VB .NET Win App

I have a very simple Insert Stored Procedure. When I run it from the Server Explorer, it inserts the records just fine. However, when I try to call it from my form, it does not update the table. The weird thing is that it does return one row effected and if I try it again, I am told my primary key is not unique (meaning the first record is in there somewhere). When I exit my app, my table is just the same as it was before the inserts. Do I need to "save" or "update" the table before closing a connection? Thanks

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.InsertNew
  2.     (
  3.     @A       nchar(10),
  4.     @B      nvarchar(50),
  5.     @C       nvarchar(50),
  6.     @D     nvarchar(50),
  7.     @E         nvarchar(50),
  8.     @F           nvarchar(50),
  9.     @G           nvarchar(50),
  10.     @H       nvarchar(50)
  11.     )
  12. AS
  13. INSERT INTO Users
  14.     (
  15.         A,
  16.         B,
  17.         C,
  18.         D,
  19.         E,
  20.         F,
  21.         G,
  22.         H
  23.     )
  24.     VALUES
  25.     (
  26.     @A,
  27.     @B,
  28.     @C,
  29.     @D,
  30.     @E,
  31.     @F,
  32.     @G,
  33.     @H
  34.     )
  35.     RETURN
  36.  
  37.  
  38.  
  39.  
  40.  
  41. Dim connection As SqlConnection
  42. connection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True")
  43. connection.Open()
  44. Dim command As SqlCommand = New SqlCommand("InsertNew", connection)
  45. command.CommandType = CommandType.StoredProcedure
  46.  command.Parameters.AddWithValue("@A", "99")
  47.  command.Parameters.AddWithValue("@B", "test")
  48.  command.Parameters.AddWithValue("@C", "test")
  49.  command.Parameters.AddWithValue("@D", "test")
  50.  command.Parameters.AddWithValue("@E", "test")
  51.  command.Parameters.AddWithValue("@F", "test")
  52.  command.Parameters.AddWithValue("@G", "test")
  53.  command.Parameters.AddWithValue("@H", "test")
  54. Dim rows
  55. rows = command.ExecuteNonQuery
  56. connection.Close()
  57.  
  58.         If (rows = 1) Then
  59.            MessageBox.Show("Create new user SUCCESS!")
  60.         Else
  61.             MessageBox.Show("Create new user FAILED!")
  62.         End If
  63.  
  64.  
May 4 '07 #1
2 983
Bumping for response
May 10 '07 #2
Motoma
3,237 Expert 2GB
This may have to do with some database settings, dealing with Transactions and Auto-commit settings.

I don't know much beyond that.
May 23 '07 #3

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

Similar topics

3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
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,...
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...

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.