Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see two insert command in your example above. The commented out command shows two values treated as numbers and not as strings.<br> You use the command text that use parameters, but all of the prepared parameters are set to the string datatype (well you don't set any datatype and this defaults the DbType property to NVarChar) Probably this is the exact error message you get when executing the insert command</p> <p>You could try the following:</p> <pre><code> Using cn As New SqlConnection(con.ConnectionString) con.Open() inscmd.Parameters.AddWitValue("@StaffInitials", lblStaffInitials.Text.Trim()) inscmd.Parameters.AddWithValue("@Week", lblWeek.Text.Trim) inscmd.Parameters.AddWithValue("@Period", Convert.ToInt32(lblPeriod.Text.Trim)) inscmd.Parameters.AddWithValue("@Day",lblDay.Text.Trim) inscmd.Parameters.AddWithValue("@Subject", lblSubject.Text.Trim) inscmd.Parameters.AddWithValue("@YearGroup", lblYear.Text.Trim) inscmd.Parameters.AddWithValue("@NumberOfPupils", Convert.ToInt32(lblNoOfPupils.Text.Trim)) inscmd.Parameters.AddWithValue("@ControlledAssesment", lblControlledAssesment.Text.Trim) inscmd.Parameters.AddWithValue("@Room",lblRoom.Text.Trim) inscmd.Parameters.AddWithValue("@Session", txtSession.Text.Trim) inscmd.CommandText = "INSERT INTO Booking ([Week], [Day], [Period], [Subject], " + "[YearGroup], [StaffInitials],[NumberOfPupils],[Session], " + "[Room],[ControlledAssesment]) "+ "VALUES " + "(@Week,@Day,@Period,@Subject,@YearGroup,@StaffInitials," + "@NumberOfPupils,@Session,@Room,@ControlledAssesment)" inscmd.Connection = con inscmd.ExecuteNonQuery() inscmd.Parameters.Clear() End Using </code></pre> <p>I have use the <a href="http://msdn.microsoft.com/en-us/library/vstudio/system.data.sqlclient.sqlparametercollection.addwithvalue%28v=vs.90%29.aspx" rel="nofollow">AddWithValue</a> method to implicitly create a parameter with a <code>DbType</code> property that is derived from the value added. So if I add a string as value, the parameter will have a <code>DbType.NVarchar</code>, but if I set an integer the DbType will be <code>DbType.Int</code>. Of course this assumes that all of your field above are of NVarChar type except <code>Period</code> and <code>NumberOfPupils</code>. If this is not true you should add the appropriate conversion to the parameter </p> <p>EDIT: Not sure, but I suspect also that DAY is a reserved keyword. Better to encapsulate the column names with square brackets </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload