Hi,
I have a web form which takes fname, lname, age and address from a user. User enters the values and clicks submit button. I want to insert the values entered by user into the database. But when i run the project. it gives the following error at conn.Open();
SqlException was unhandled by user code:
Cannot open database "EmployeeRecordSystem" requested by the login. The login failed.
Login failed for user 'FAISALPC\ASPNET'.
Below is my code of connecting to database and storing values into it.
string fname = TextBox1.Text;
string lname = TextBox2.Text;int age = int.Parse(TextBox3.Text);
string address = TextBox4.Text;SqlConnection conn = new SqlConnection();conn.ConnectionString = @"Data Source=FAISALPC\SQLEXPRESS;Initial Catalog=EmployeeRecordSystem;Integrated Security=True";
conn.Open();
string query = "INSERT INTO Employee (Fname, Lname, Age, Address) VALUES (' " + fname + "', '" + lname + "', '"+ age + "', '" + address + "')";SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
conn.Close();