Click here to Skip to main content
15,904,935 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
protected void Button1_Click(object sender, EventArgs e)
    {

        SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\gnani\websites\iconlabssite part2\App_Data\maindatabase.mdf;Integrated Security=True;");
        SqlCommand insert = new SqlCommand("insert into regform(username, password, mobileno,emailid) values(@username, @password, @phoneno,@emailid)", conn);
        insert.Parameters.AddWithValue("@username", TextBox1.Text);
        insert.Parameters.AddWithValue("@password", TextBox2.Text);
        insert.Parameters.AddWithValue("@phoneno", TextBox4.Text);
        insert.Parameters.AddWithValue("@emailid", TextBox5.Text);
        try
        {
            conn.Open();
            insert.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            LMsg.ForeColor = System.Drawing.Color.Red;
            LMsg.Text = "Error when saving on database";
            conn.Close();
        }
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
    }
Posted
Updated 23-Dec-13 19:07pm
v3
Comments
JoCodes 24-Dec-13 1:08am    
Any error you got?
Karthik_Mahalingam 24-Dec-13 2:01am    
error message ??
member 8888995 24-Dec-13 3:50am    
Please paste your error.

1 solution

Have a look here: SQL Server Connection Strings for ASP.NET Web Applications[^], choose your version of MS SQL Server and check if the connection string is properly set.
 
Share this answer
 
Comments
Member 12373536 6-Mar-16 18:05pm    
Pls some one should help me out here...i am doing my school project and my php is not connecting to my data base...
Here is my code


why here is the error msg


Warning: mysql_connect(): Access denied for user 'u562528242_love'@'localhost' (using password: YES) in /home/u562528242/public_html/project/loveword/database.php on line 10 MySQL connect failed. Access denied for user 'u562528242_ delh'@'localhost' (using password: YES)

Pls some one help me out..
Maciej Los 6-Mar-16 18:28pm    
You should post it as new question. Do not post comments not related to solution.

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