Hi,I am new to .net, i write the select statement for session as like
Session["RoleId"] = "select roleid from AdminLogin where username='" + txtUserName.Text + "'";
but i m getting error what is problem with this.
Thanks in advance...
Hi,I am new to .net, i write the select statement for session as like
Session["RoleId"] = "select roleid from AdminLogin where username='" + txtUserName.Text + "'";
but i m getting error what is problem with this.
Thanks in advance...
I'm betting he's getting an error because his single quotes aren't escaped. It should be:
Session["RoleId"] = "select roleid from AdminLogin where username=\'" + txtUserName.Text + "\'";
However, it should be noted that Raghu probably wants to exec the thing. Look at the SqlCommand class and related examples.
Do you really intend to store the select statement in the session variable, or you want to retrieve a value from a database instead? In the later case, you need to use a database access engine such as ADO.NET or LINQ to SQL.
Your SQL string looks structured ok, so I would suggest running the SQL generated directly in SQL Server to see if you get the error there.
If not, the problem is probably in your code.
Of course as the comments on your post have mentioned, if you post the error message, it will make ouit easier for us to work out what the problem is.