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

Help needed for new vb.net user

Hi all

Can someone please post some sample code to get me going. I have a simple table which I would like to add a new record to and have the Identity of the new row passed back to me. The table is called “ContactGroups” and it has 2 fields intID and GroupName. (Database on SQL Server 2000

I have managed to do the insert, but It is not giving me the Identity back. The code I have used is as follows, but I am sure there is a better way to do this. I have only been using VB.Net for a month and am struggling to get my head around it

Dim ReturnedID as Intege
Dim newConn as New Data.SqlClient.SqlComman

Dim cmd as New Data.SqlClient.SqlComman
Dim prmIn as New Data.sqlClient.SqlParamete
Dim prmOut as New Data.sqlClient.SqlParamete

newConn.ConnectionString = strCon

prmIn.dbType = dbType.Strin
prmIn.Direction = ParameterDirection.Inpu
prmIn.Value = “Test

prmOut.dbType = dbType.Int1
prmOut.Direction = ParameterDirection.Outpu

newConn.Open(

With cm
.CommandText = “InsGroup
.CommandType = CommandType.StoredProcedur
.Parameters.Add(prmIn
.Paramiters.Add(prmOut
.Connection = newCon

.ExecuteNonQuery(
End Wit

ReturnedID = cmd.Parameters(“prnOut”).Valu

Stored Procedure Cod

Create Procedure [dbo].[InsGroup

@Data VARCHAR(30)
@intID INT OUTPU

A

INSERT INTO ContactGroups (ContactGroup) VALUES (@Data

SET @intID = SCOPE_IDENTITY(
G

When I run the code I get an error stating that Parameter 1 is not a parameter for procedure InsGrou

Am I on the right track with this, or should I be doing this in a totally different way? Can the same be done without using Stored Procedures?

Any help would be great, especially if someone would be kind enough to post a code sample of a better way of doing this

Thank You

Mar

Jul 21 '05 #1
0 950

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Chirico | last post by:
Hopefully this will help someone... Helpful Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Last Updated: Fri Apr 16 11:47:34 EDT 2004 The latest version of this...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
8
by: . . | last post by:
Hi I am developing a web system using ASP.NET/VB.NET with SQL Server 2005 as back end database . I need to develop a aspx page where user can see their messages after they log into the system...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
2
by: Steve K | last post by:
I got a bit of a problem I like some help on. I'm designing an online training module for people that work in food processing plants. This is my target audience. These workers have little or no...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
7
by: isdeveloper | last post by:
Hi All, I have a problem with a table that I want to get nice data out of in a single query. The guys here reckon it can't be done in a single query but I wanted to prove them wrong !!...
8
by: 08butoryr | last post by:
Hey guys I could really use your help with some very basic java programming. I know you programming fundis out there will find this child's play but I'm struggling with it a bit because I'm...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.