Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello Everyone My code is as follows....

protected void Button4_Click(object sender, EventArgs e)
{
string strpassword = Encryptdata(TextBox5.Text);
SqlConnection conn = new SqlConnection();
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["leave"].ConnectionString;
conn.Open();
SqlCommand cmd = new SqlCommand("insert into emp_details VALUES('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + strpassword + "','" + DropDownList1.SelectedValue.ToString() + "','" + TextBox4.Text + "')", conn);
cmd.ExecuteNonQuery();

}
private string Encryptdata(string password)
{
string strmsg = string.Empty;
byte[] encode = new byte[password.Length];
encode = Encoding.UTF8.GetBytes(password);
strmsg = Convert.ToBase64String(encode);
return strmsg;
}

further,in database,type for password field is nvarchar(100).The highlighted line is giving me error if i enter Character such as @ in password,that String or binary data would be truncated. The statement has been terminated.
Why this is so?Any help would be greatly appriciated....
Posted
Updated 13-Feb-13 18:30pm
v3
Comments
Nandakishore G N 14-Feb-13 0:51am    
have you handled exception in stored procedure?
Thanks7872 14-Feb-13 0:52am    
no...the problem is somewhere with encrypting the password....i am not able to figure it out....can you help me in this regard...?
Thanks7872 14-Feb-13 2:07am    
can you help me which datatype in sql server database would allow special characters like @?
Nandakishore G N 14-Feb-13 7:45am    
this error general occurs the data you are passing is more than the assigned value in the table.no problem with nvarchar..because even after base64encoding the pwd length will be 22 chars..

1 solution

change your password field to varchar(max) ... "',N'" + strpassword + "' according to me there is some problem ....
 
Share this answer
 
Comments
Thanks7872 14-Feb-13 0:33am    
thanks for your reply,but it still doesnt work...i have also removed N see the updated question...any other suggessions please?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900