Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void Button1_Click1(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
con.Open();
string insertQuery = "insert into UserData(User Name,Email,Password,Country)values(@Uname,@Email,@Password,@Country)";
SqlCommand com = new SqlCommand(insertQuery, con);
com.Parameters.AddWithValue("@Uname", TextBoxUN.Text);
com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
com.Parameters.AddWithValue("@password", TextBoxPass.Text);
com.Parameters.AddWithValue("@country", DropDownListCountry.SelectedItem.ToString());

com.ExecuteNonQuery();
Response.Redirect("Mnager.aspx");
Response.Write("Registration is Successfull..........");

con.Close();
}
catch (Exception ex)
{
Response.Write("Error:" + ex.ToString());
}
Posted
Comments
Ramug10 27-Feb-14 1:06am    
Show me your error..
harshavardhan12345678 27-Feb-14 1:07am    
User already ExistsError:System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'User'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Registrationaspx.Button1_Click1(Object sender, EventArgs e) in c:\Users\MR002\Documents\Visual Studio 2010\WebSites\LoginWebsite1\Registrationaspx.aspx.cs:line 41
harshavardhan12345678 27-Feb-14 1:47am    
thanks bro
Ramug10 27-Feb-14 1:57am    
You most welcome always..
harshavardhan12345678 27-Feb-14 6:01am    
protected void Button_Login_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
con.Open();
string checkuser = "select count(*) from UserData where [User Name]='" + TextBoxUserName.Text + "'";
SqlCommand com = new SqlCommand(checkuser, con);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
con.Close();
if (temp == 1)
{
con.Open();
string checkPasswordQuery = "select password from UserData where [User Name]'" + TextBoxUserName.Text + "'";
SqlCommand passcom = new SqlCommand(checkPasswordQuery, con);
string password = passcom.ExecuteScalar().ToString().Replace(" ","");
if (password == TextBoxPassword.Text)
{
Session["New"] = TextBoxUserName.Text;
Response.Write("Password is correct");
Response.Redirect("Mnager.aspx");
}
else
{
Response.Write("password is not correct");
}

Use the below code..

protected void Button1_Click1(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
                con.Open();
                string insertQuery = "insert into UserData([User Name],Email,Password,Country)values(@Uname,@Email,@Password,@Country)";
                SqlCommand com = new SqlCommand(insertQuery, con);
                com.Parameters.AddWithValue("@Uname", TextBoxUN.Text);
                com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
                com.Parameters.AddWithValue("@password", TextBoxPass.Text);
                com.Parameters.AddWithValue("@country", DropDownListCountry.SelectedItem.ToString());

                com.ExecuteNonQuery();
                Response.Redirect("Mnager.aspx");
                Response.Write("Registration is Successfull..........");

               
            }
            catch (Exception ex)
            {
                Response.Write("Error:" + ex.ToString());
            }
            finally
            {
                con.Close();
            }
        }
 
Share this answer
 
Check the answer to your previous question , its the same solution .

iam getting error in defaul.aspx.cs page[^]
 
Share this answer
 
v2

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