Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Insert VB.NET
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Titre:
SQL Insert VB.NET
Divers
Thread ID:
00703626
Message ID:
00703626
Vues:
37
I have a very simple insert that refuses to behave. The issue is the datetime field [eventdate] walking through the code the date is as we would expect, a system.datetime showing a value of say #12/10/2002#, however, after the insert the date in the table is 1/1/1900 12:00 AM :( The SQL user has full datareader/datawriter rights. I Was hoping someone here would see the err of my ways. The database is a remote SQL 2000 server (SP2) running on windows 2000. Eventdate is a datetime field in SQL. I have also tried using a character var on the VB side.
Private Sub AddNewRegistry()

        Dim strInsSQL As String
        Dim RegistrantUID, iRegistryType As Integer
        Dim datEvent As DateTime

        RegistrantUID = DeCrypt(Session("RegistrantUID"))
        iRegistryType = cboRegistryTypes.Items(cboRegistryTypes.SelectedIndex).Value
        datEvent = txtEventDate.Text
        strInsSQL = "INSERT INTO Registry (RegistryName, RegistryDesc, EventDate, RegType_ID, Registrant_ID) " & _
                                "Values ('" & _
                    txtRegistryName.Text.Trim & "', '" & _
                    txtRegistryDesc.Text.Trim & "', Cast(" & _
                    datEvent & " as datetime) , " & _
                    iRegistryType & ", " & _
                    RegistrantUID & ")"

        Dim oCn As New SqlConnection(SQLcn.ConnectionString.ToString)
        Dim dbComm As New SqlCommand(strInsSQL, oCn)
        oCn.Open()
        dbComm.ExecuteNonQuery()
        oCn.Close()
        ClearRegistryEntry()
        'BindGrid(Session("SORTFIELD"))3
    End Sub
~Joe Johnston USA

"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams

Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform