Loading ...

Help with inserting url into db on button click event

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  web forms / data controls   » Help with inserting url into db on button click event

Help with inserting url into db on button click event

Posts under the topic: Help with inserting url into db on button click event

Posted: 9/21/2011

Lurker 360  points  Lurker
  • Joined on: 6/5/2011
  • Posts: 51

here is my code:

string imageVar="[unknown]";
            switch (Rating1.CurrentRating)
            {
                case 0: 
                   imageVar = "~/Images.emptystar.png";
                    break;
                case 1:
                   imageVar = "~/Images.Onestar.png";
                    break;
                case 2:
                    imageVar = "~/Images.Twostar.png";
                    break;
                case 3:
                    imageVar = "~/Images.Threestar.png";
                    break;
                case 4:
                    imageVar = "~/Images.Fourstar.png";
                    break;
                case 5:
                    imageVar = "~/Images.Fivestar.png";
                    break;

            }


            SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\SunRest.mdf;Integrated Security=True;User Instance=True");
            SqlCommand cmd = new SqlCommand();
            string query = "INSERT INTO RateUs (Image) VALUES (@Image)";

            cmd.CommandText = query;
            cmd.CommandType = CommandType.Text;

            
                cmd.Parameters.AddWithValue("@Image", imageVar);
                cmd.Connection = conn;
                conn.Open();
                cmd.ExecuteNonQuery();

I got an exception that the insert table name is different than the table definition and it highlights that last line cmd.ExecuteNonQuery();

 

thanks in advance!


Posted: 9/21/2011

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

Run SQL profile and try executing the same query in SSMS Query Analyzer, you can track the cause from there.


Page 1 of 1 (2 items)