-5

This is the error

Server Error in '/Kibritak3' Application.

Invalid column name 'Name'. Invalid column name 'Phone'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'Name'. Invalid column name 'Phone'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

its just come if i write this code
 **

if (Literal1.Text == "Data inserted successfully")
        {
            Response.Redirect("http://localhost:1038/Kibritak3/CompanyHomePage.aspx");
        }
        else {
            txtName.Text = "";
            txtEmail.Text = "";
            txtPhone.Text = "";
        }

**
and without it evrything is ok
-------------------------
full code:
    public void refress()
    {
        txtName.Text = "";
        txtEmail.Text = "";
        txtPhone.Text = "";
        txtLocation.Text = "";
        txtHistory.Text = "";
    }




    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
         SqlCommand cmd = new SqlCommand("insert into Com_INFO(Name,Email,Phone,Location,History) values('" + txtName.Text + "','" + txtEmail.Text + "','" +txtPhone.Text+ "','" +txtLocation.Text+ "','"+txtHistory.Text+"')", con);

        cmd.CommandType = CommandType.Text;

        try
        {

            con.Open();

            cmd.ExecuteNonQuery();

            Literal1.Text = "Data inserted successfully";

            con.Close();

            refress();

        }

        catch (Exception ex)
        {

            Literal1.Text = ex.Message;

        }
        if (Literal1.Text == "Data inserted successfully")
        {
            Response.Redirect("http://localhost:1038/Kibritak3/CompanyHomePage.aspx");
        }
        else {

            txtName.Text = "";
            txtEmail.Text = "";
            txtPhone.Text = "";
        }
    }
}
Frank
  • 47
  • 10
Al-wahidi
  • 1
  • 3
  • 5
    That's not a stack trace. – Sani Huttunen Apr 14 '15 at 17:47
  • Your database table doesn't have the columns you think it does. Also, for the love of sanity, learn to use parameters... especially in a web application! http://stackoverflow.com/q/17509169/327083 – J... Apr 14 '15 at 17:47
  • 1
    Without seeing the the structure of the table(s) you're accessing in your database, there's not much more we can say other than your database column names don't match the names you're referencing in your code, which is exactly what the error message is telling you. Also, J... is correct. The code shown in your question should **never** be put into production. It is dangerous. – hatchet - done with SOverflow Apr 14 '15 at 17:48
  • dear Sani ... i have a columns and i say before the data is saving fine without if statement – Al-wahidi Apr 14 '15 at 17:56
  • Put a breakpoint on the `Literal1.Text = "Data inserted successfully";` line, and let us know if the breakpoint ever actually gets hit. – hatchet - done with SOverflow Apr 14 '15 at 18:02

3 Answers3

0

please verify the attributes of your database once. OR do not include the attributes of your table in your query.

SqlCommand cmd = new SqlCommand("insert into Com_INFO values('" + txtName.Text + "','" + txtEmail.Text + "','" +txtPhone.Text+ "','" +txtLocation.Text+ "','"+txtHistory.Text+"')", con);

0

As the error message points out (and other contributors), you do not have the columns 'name' and 'phone' in your database. Also, as a side note, never write the actual sql query in the code. Write it in a stored proc and then invoke the stored proc from the code.

0

Can you check once again your DB? I think you have just added those columns in your database and all you need to do is refresh your database. And please use Parameters when you're processing DML Commands in your program to secure your data/database.

JC Borlagdan
  • 3,318
  • 5
  • 28
  • 51