Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have creatng the web base project online quiz system which have Admin, Faculty members, students , Admin have registered the faculty members and student , faculty create the quiz and student take quiz and view result ,
when i have trying to insert faculty data into data base the error occurred
(Invalid object name 'tbl_faculty_). tbl_faculty is the table name in my data base .

What I have tried:

protected void btnInsert_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=file_record;Integrated Security=True"))
{
SqlCommand CmdSql = new SqlCommand("INSERT INTO [tbl_faculty] (fac_name,fac_password,fac_ID,fac_dep) VALUES (@fac_name,@fac_password,@fac_ID,@fac_dep)", conn);
conn.Open();
CmdSql.Parameters.AddWithValue("@fac_name", facname.Text);
CmdSql.Parameters.AddWithValue("@fac_password", Password.Text);
CmdSql.Parameters.AddWithValue("@fac_id", facultyID.Text);
CmdSql.Parameters.AddWithValue("@fac_dep", ddDeptName.SelectedItem.Value);
//CmdSql.Parameters.AddWithValue("@Year", TextBox5.Text);
//CmdSql.Parameters.AddWithValue("@Description", TextBox6.Text);
CmdSql.ExecuteNonQuery();
conn.Close();
}
Posted
Updated 20-Apr-17 9:20am

1 solution

Look closely at you posted code, specifically that following line:
using (SqlConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=file_record;Integrated Security=True"))

That is not a valid connection string. You need to provide the server and db name. You can checkout http://www.connectionstrings.com for a reference.
 
Share this answer
 
Comments
Richard Deeming 9-May-17 10:30am    
Actually, it's perfectly valid. Data Source specifies the server, and Initial Catalog specifies the database name.

SqlConnection.ConnectionString Property[^]

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