RunePerstrup
asked on
Storing additional user information i MSSQL using the CreateUserWizard
Hi there!
I am trying to store some user information using the CreateUserWizard in addition to the information which is otherwise stored in the membershipdb ASPNETDB.mdf (First name, last name, address etc.). This information will be stored in another MSSQL2005-database.
The strategy is to gather the information from a number of textboxes in a CreateUserWizard and add the information to a table.
The code below shows what I've got. Unfortunately I get the following error messages
The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?)
The name 'ConnectionString' does not exist in the current context.
Can anyone explain this (and give a sollution)?
protected void CreateUserWizard1_Creating User(objec t sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection(ConnectionSt ring);
string Q_ADD_USER = @"INSERT INTO Users(UserName, FirstName, LastName) VALUES (@UserName, @FirstName, @LastName)";
SqlCommand myCommand = new SqlCommand(Q_ADD_USER, myConnection);
string userName = CreateUserWizard1.UserName ;
string firstName = ((TextBox)CreateUserWizard 1.CreateUs erStep.Con tentTempla teContaine r.FindCont rol("txtFi rstName")) .Text;
string lastName = ((TextBox)CreateUserWizard 1.CreateUs erStep.Con tentTempla teContaine r.FindCont rol("txtLa stName")). Text;
myCommand.Parameters.AddWi thValue("@ UserName", userName);
myCommand.Parameters.AddWi thValue("@ FirstName" , firstName);
myCommand.Parameters.AddWi thValue("@ LastName", lastName);
myConnection.Open();
myCommand.ExecuteNonQuery( );
myConnection.Close();
}
I am trying to store some user information using the CreateUserWizard in addition to the information which is otherwise stored in the membershipdb ASPNETDB.mdf (First name, last name, address etc.). This information will be stored in another MSSQL2005-database.
The strategy is to gather the information from a number of textboxes in a CreateUserWizard and add the information to a table.
The code below shows what I've got. Unfortunately I get the following error messages
The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?)
The name 'ConnectionString' does not exist in the current context.
Can anyone explain this (and give a sollution)?
protected void CreateUserWizard1_Creating
{
SqlConnection myConnection = new SqlConnection(ConnectionSt
string Q_ADD_USER = @"INSERT INTO Users(UserName, FirstName, LastName) VALUES (@UserName, @FirstName, @LastName)";
SqlCommand myCommand = new SqlCommand(Q_ADD_USER, myConnection);
string userName = CreateUserWizard1.UserName
string firstName = ((TextBox)CreateUserWizard
string lastName = ((TextBox)CreateUserWizard
myCommand.Parameters.AddWi
myCommand.Parameters.AddWi
myCommand.Parameters.AddWi
myConnection.Open();
myCommand.ExecuteNonQuery(
myConnection.Close();
}
Sound like you are missing the "using" directive for the System.Data.SqlClient namespace. Add the following at the top of your code file:
using System.Data.SqlClient;
Or, fully-qualify your object types in code:
System.Data.SqlConnection myConnection = new System.Data.SqlConnection( Connection String);
using System.Data.SqlClient;
Or, fully-qualify your object types in code:
System.Data.SqlConnection myConnection = new System.Data.SqlConnection(
ASKER
Great start. Seams like I still have a lot to learn...
For some reason I can't get the compiler to accept the "using" anywhere in the code, because it is an "invalid token"... I can still use the fully-qualify your object types though.
Anyway, I still have a problem with the connection string. It says "The name 'ConnectionString' does not exist in the current context.". How can I access the correct context?
For some reason I can't get the compiler to accept the "using" anywhere in the code, because it is an "invalid token"... I can still use the fully-qualify your object types though.
Anyway, I still have a problem with the connection string. It says "The name 'ConnectionString' does not exist in the current context.". How can I access the correct context?
Presumably you have ConnectionString defineds as a variable somewhere. Where is it in relation to the code you posted ?
Also:
using System.Data.SqlClient;
needs to go at the very top of the code file, outside of any classes/methods, etc.
Also:
using System.Data.SqlClient;
needs to go at the very top of the code file, outside of any classes/methods, etc.
ASKER
The connectionstring is defined in the web.config file - and I am trying to access it from my code which is executed when a CreateUserWizard1_Creating User occurs in a web page.
.Net 1.1 or 2.0 ?
ASKER
ASP.NET 2.0
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That is just so wonderful!
Thank you!
Thank you!
ASKER
The second error message goes like this:
The type or namespace name 'SqlCommand' could not be found (are you missing a using directive or an assembly reference?)