Click here to Skip to main content
15,904,655 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi guys.
bit of a problem i have come across on my final page, i am taking information which are integers from drop down menus which are, in turn linked to their own data sources.
and then writing these intergers to a different table which are the same types (int) as the tables they are coming from, even then i am changing them to strings during the parameter:

C#
<pre lang="cs">protected void confirmFixedHolButton0_Click(objectsender, EventArgs e)
        {
            using (conn)
            {
                conn.Open();
                SqlCommand insertHolBooking = new SqlCommand("INSERT INTO [HolidayBooking] ([Customer ID], [Fixed Holiday ID], [Holiday ID], [Flight ID], [Holiday Tour ID])
 VALUES 
(@customerID, @fixHolID, @holID, @flightID, @holTourID)", conn);
                insertHolBooking.CommandType = CommandType.Text;

                insertHolBooking.Parameters.AddWithValue("@customerID", customerIDDDM.SelectedItem.ToString());
                insertHolBooking.Parameters.AddWithValue("@fixHolID", fixedHolDDL.SelectedItem.ToString());
                insertHolBooking.Parameters.AddWithValue("@holID", holidayIDDDM.SelectedItem.ToString());
                insertHolBooking.Parameters.AddWithValue("@flightID", flightIDDDM.SelectedItem.ToString());
                insertHolBooking.Parameters.AddWithValue("@holTourID", tourIDDDM0.SelectedItem.ToString());

                try
                {   conn.Open();
                    insertHolBooking.ExecuteNonQuery();
                    Response.Redirect("Bookings.aspx");
                }
                catch (Exception)
                {   Response.Write("<b>Failed please try again.</b>");
                }
            }
        }



it always throws the error message, cant see anything wrong with the SQL nor with the parameter.

The table this information is being written to is allowing nulls so i cant see the problem...

please help guys
Regards
Matt.
Posted
Comments
jim lahey 18-Apr-12 9:30am    
Post the exception.
[no name] 18-Apr-12 9:46am    
If the data in the tables are integers, why are you casting them to strings when trying to write them back into the database?

1 solution

Solved, i repeated the conn.Open(); twice in the Using() statement

thanks guys, sorry for wasting ur time

Regards
Matt.
 
Share this answer
 
Comments
Nelek 18-Apr-12 17:50pm    
Nice to hear that you solved it. Have fun

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