Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 21st, 2006, 08:02 AM
Authorized User
 
Join Date: Aug 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default INSERT Data to SQL Database

I Have a reg page where user can reg.
But now I have problems with insert.
What is the problem here.
Can someone help me
The table where I want to store values are named login and have columns(UID=Identity, Username, Password, Active, Email, Activationcode)
Dim loConn as SqlConnection
Dim myCommand as SqlCommand
Dim InsertCmd as String
loConn = New SqlConnection("Server=******; database=****; UID=****; PWD=*******")
insertCmd = "insert into Login values (@Username, @Password, @email, @Activationcode);"
myCommand = New SqlCommand(InsertCmd, loConn)
myCommand.Parameters.Add(New SqlParameter("@UID", SqlDBType.int))
myCommand.Parameters("@UID").Direction = ParameterDirection.Output
myCommand.Parameters.Add(New SqlParameter("@Username", SqlDbType.nVarChar, 50))
myCommand.Parameters("@Username").value = Username.value
myCommand.Parameters.Add(New SqlParameter("@Password", SqlDbType.nVarChar, 50))
myCommand.Parameters("@Password").value = Password.value
myCommand.Parameters.Add(New SqlParameter("@email", SqlDbType.nVarChar, 50))
myCommand.Parameters("@email").value = email.value
myCommand.Parameters.Add(New SqlParameter("@Active", SqlDbType.int))
myCommand.Parameters("@Active").value = "0"
myCommand.Parameters.Add(New SqlParameter("@Activationcode", SqlDbType.nVarChar, 50))
myCommand.Parameters("@Activationcode").value = activecode.value
myCommand.Connection.open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()

 
Old February 22nd, 2006, 03:09 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your INSERT cmd states:

"insert into Login values (@Username, @Password, @email, @Activationcode);"

You then attempt the following, without declaring @Active in your INSERT statement:

myCommand.Parameters("@Active").value = "0"
myCommand.Parameters.Add(New SqlParameter("@Activationcode", SqlDbType.nVarChar, 50))

This should surely give you an error as @Active is not declared in your SQL statement.

- A.Kahtava





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to insert text file in sql server database sharvari_mothe Java Databases 3 June 5th, 2007 07:25 AM
Check before insert data into sql Alcapone C# 2 October 26th, 2004 07:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.