I am inserting data into sql server 2008 database. The table name i am providing is exist in database.
I had also tried by dbo.tablename. I checked my web.config file setting also. still i am not able to insert in the table.
Please help me. My code is as follows:
protected void
btnSave_Click(object
sender, EventArgs
e)
{
try
{
Student stud =
new
Student();
stud.FirstName = txtFirstName.Text;
stud.LastName = txtLastName.Text;
stud.LoginName = txtEmailID.Text;
stud.LoginPassword = txtPassword.Text;
stud.Gender = rdbMale.Text;
stud.MobileNo = txtMobileNo.Text;
stud.Country = ddlCountry.SelectedItem.Value;
stud.State = ddlState.SelectedItem.Value;
stud.City = ddlCity.SelectedItem.Value;
stud.Education = ddlEducation.SelectedItem.Value;
stud.Comment = txtComment.Text;
stud.EnqueryStatus =
"Waiting for approval";
stud.Created =
DateTime.Now;
stud.addEnquiry(stud);
lblMessage.Text
="Data
saved";
}
catch
(Exception
ex)
{
lblMessage.Text = ex.Message;
}
}
Student.cs
public
void
addEnquiry(Student
stud)
{
string
query = "insert into Enquiry_Student(SE_First_Name,
SE_Last_Name, SE_Login_Name, SE_Password, SE_Gender, SE_Mobile_No, SE_Country, SE_State, SE_City, SE_Enquiry_Status, SE_Comment, SE_Creation_Date) values(@FirstName, @LastName, @LoginName, @Password, @Gender, @MobileNo, @Country, @State, @City, @EnqueryStatus,
@Comment, @CreationDate)";
DBHandler
dbHandler = DBHandler.getInstance();
SqlConnection
con = new
SqlConnection(dbHandler.connString);
SqlCommand
command = new
SqlCommand(query,
con);
command.Parameters.Add("@FirstName",
SqlDbType.VarChar).Value
= stud.FirstName;
command.Parameters.Add("@LastName",
SqlDbType.VarChar).Value
= stud.LastName;
command.Parameters.Add("@LoginName",
SqlDbType.VarChar).Value
= stud.LoginName;
command.Parameters.Add("@Password",
SqlDbType.VarChar).Value
= stud.LoginPassword;
command.Parameters.Add("@Gender",
SqlDbType.VarChar).Value
= stud.Gender;
command.Parameters.Add("@MobileNo",
SqlDbType.VarChar).Value
= stud.MobileNo;
command.Parameters.Add("@Country",
SqlDbType.VarChar).Value
= stud.Country;
command.Parameters.Add("@State",
SqlDbType.VarChar).Value
= stud.State;
command.Parameters.Add("@City",
SqlDbType.VarChar).Value
= stud.City;
command.Parameters.Add("@EnqueryStatus",
SqlDbType.VarChar).Value
= stud.EnqueryStatus;
command.Parameters.Add("@Comment",
SqlDbType.VarChar).Value
= stud.Comment;
command.Parameters.Add("@CreationDate",
SqlDbType.Date).Value
= stud.Created;
using(con)
{
con.Open();
dbHandler.ExecuteNonQuery(command);
}
}
DBHandler.cs
public void
ExecuteNonQuery(SqlCommand
command)
{
try
{
catch
(Exception ex)
{
throw ex;
}
My
database table is as follows

}
command.ExecuteNonQuery(); //Here i am getting error "Invalid object name 'Enquiry_Student'"
}