Showing posts with label password. Show all posts
Showing posts with label password. Show all posts

Monday, March 26, 2012

Insert with Parameters (SQL Server)

Hello, this is my code:

SqlCommand cmd =new SqlCommand("INSERT INTO Users (Username,Password) " +"VALUES ('@.username','@.password' ",new SqlConnection(my_ConnectionString)); cmd.Parameters.Add("@.username", SqlDbType.NVarChar, 50).Value = txtUsername.Text;cmd.Parameters.Add("@.password", SqlDbType.NVarChar, 50).Value = txtPassword.Text cmd.Connection.Open();cmd.ExecuteNonQuery();cmd.Connection.Close();

But in the database, the row inserted is exactly this:

"@.username" "@.password"

I mean, the parameters are not inserted :S

Please, tell me the error in the code...
Thank you so much,

Carlos.Placing single quotes around the parameters makes them be treated as literal strings. Remove the single quotes and you should have better luck.|||Thank you, now it works ;)

Carlos.

Friday, March 23, 2012

insert value into 2 columns,1 col. should take data from another table & 2nd random

Hi,

I have table which has 2 columns
username
password

i want to insert username values from by copying data from another table whereas password shd be randomly generated

Thank You

Quote:

Originally Posted by parshupooja

Hi,

I have table which has 2 columns
username
password

i want to insert username values from by copying data from another table whereas password shd be randomly generated


Thank You



Are you looking at doing this directly in MySQL, or do you have a thin/fat client you would like to do this through? I don't believe there is a random text function in MySQL, but many programming languages have ways to accomplish it.|||i am working SQL Server 2005. yes need to do it directly

Quote:

Originally Posted by ilearneditonline

Are you looking at doing this directly in MySQL, or do you have a thin/fat client you would like to do this through? I don't believe there is a random text function in MySQL, but many programming languages have ways to accomplish it.