i'm working on asp, vs2005. I should save the typed information in sql server. I connected and written the code in the following way

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim ConnStr As String
        Dim visitors_name, officer_to_visit, purpose, date_of_visit, time_in As String
        Dim serial_no, year, floor As Integer
        ConnStr = ConfigurationManager.ConnectionStrings("gate").ConnectionString()

        Dim conn As New SqlConnection(ConnStr)

        serial_no = serialno.Text
        year = years.Text
        visitors_name = visitorsname.Text
        officer_to_visit = officertovisit.Text
        purpose = pur.Text
        date_of_visit = dateofvisit.Text
        floor = wing.Text
        time_in = timein.Text

        Dim adapter As New SqlClient.SqlDataAdapter("select serial_no,year,visitors_name,officer_to_visit,purpose,date_of_visit,floor,time_in,time_out from visitors_pass", conn)
        Dim insert As New SqlClient.SqlCommand("insert into visitors_pass (serial_no,year,visitors_name,officer_to_visit,purpose,date_of_visit,floor,time_in,time_out) Values('" & serial_no & "' ,'" & year & "', '" & visitors_name & "','" & officer_to_visit & "','" & purpose & "','" & floor & "','" & date_of_visit & "','" & time_in & "')", conn)

        WriteLine("record saved")

    End Sub

but when i run it is showing an exceptional like
System.FormatException: Input string was not in a correct format.
and pointing towards
serial_no = serialno.Text

anyone plz can you tell where the error occured in the code and rectify it. I need it very urgently

7 Years
Discussion Span
Last Post by mail2saion

The values for date_of_visit and floor columns are specified in wrong order in the VALUES clause. Also value is not specified for time_out column.


in this same code what does this mean
violation of PRIMARY KEY constraint 'PK_visitors_pass'. Cannot insert duplicate key in object 'dbo.visitors_pass'.
The statement has been terminated.
here the primary keys are serial_no and year


You mus insert unique value for serial_no & year combindly.

PK_visitors_pass is the constraint name for serial_no & year.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.