Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15229

[RESOLVED] Data not inserted in the Database

$
0
0
Hi,

The following code executes without error but refreshing the database record not inserted. It does tell me that 'New Tenant has been added'

Code:

  Dim command As New SqlCommand("INSERT INTO dbo.tbltenants (firstName, lastName, tenantfullname, telephone, email, nationalid, copyID) VALUES (@firstName, @lastName, @tenantfullname, @telephone, @email, @nationalid, @copyID)", conn)

                Dim ms As New MemoryStream
                PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)

                command.Parameters.Add("@firstname", SqlDbType.VarChar).Value = TxtFName.Text
                command.Parameters.Add("@lastname", SqlDbType.VarChar).Value = TxtLName.Text
                command.Parameters.Add("@tenantfullname", SqlDbType.VarChar).Value = TxtFName.Text & " " & TxtLName.Text
                command.Parameters.Add("@telephone", SqlDbType.NVarChar).Value = TxtTel.Text
                command.Parameters.Add("@email", SqlDbType.NVarChar).Value = TxtEmail.Text
                command.Parameters.Add("@nationalID", SqlDbType.NVarChar).Value = TxtNationalID.Text
                command.Parameters.Add("@copyID", SqlDbType.Image).Value = ms.ToArray()

            '    cmd.ExecuteNonQuery()
            'Catch ex As Exception
            '    MsgBox(ex.Message, MsgBoxStyle.Information, "RCMS")
            'End Try

            MsgBox("New Tenant has been added", MsgBoxStyle.Information, "RCMS")
            Me.Close()

        End If

        conn.Close()
        conn.Dispose()

End Sub

At the start of the Dub I have:

Code:

        Dim conn As SqlConnection = GetDbConnection()
        Dim query As String
        Dim cmd As New SqlCommand

Where am I doing wrong ?

Thanks,

Viewing all articles
Browse latest Browse all 15229

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>