no data in my database

By ofemigan ·
Hello i am a young programmer with a lot of pressure to deliver fast.
My problem is with a simple code i wrote to insert data into a database and it is runs thru but there is no data in my database . i dont know what could be wrong
Imports System.Data.SqlClient

Public Class Form1

Public Sub addNewRecords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addNewRecords.Click

If InsertData(assetcode.Text, fullName.Text, modelNo.Text, unitNo.Text, make.Text, yearOfManufacture.Text) = True Then
MessageBox.Show("Insert successful")

MessageBox.Show("An error Has occured During Insertion")
End If

End Sub
Public Function InsertData(ByVal assetCode As Integer, ByVal fullName As String, ByVal modelNo As String, ByVal unitNo As String, ByVal make As String, ByVal yearOfManufacture As Date) As Boolean

Dim strSql As String = "Insert Into Asset2(AssetCode,Fullname,ModelNo,UnitNo,Make,YearOfManufacture)Values(@AssetCode,@Fullname,@ModelNo,@UnitNo,@Make,@YearOfManufacture)"
Using cnn As New SqlConnection(My.Settings.KEngDatabase2ConnectionString)
Using cmd As New SqlCommand(strSql, cnn)
cmd.CommandType = CommandType.Text
Dim prm As SqlParameter

prm = New SqlParameter("@AssetCode", SqlDbType.Int)
prm.Value = assetCode

prm = New SqlParameter("@Fullname", SqlDbType.NVarChar, 50)
prm.Value = fullName

prm = New SqlParameter("@ModelNo", SqlDbType.NVarChar, 50)
prm.Value = modelNo

prm = New SqlParameter("@UnitNo", SqlDbType.NVarChar, 50)
prm.Value = unitNo

prm = New SqlParameter("@Make", SqlDbType.NVarChar, 50)
prm.Value = make

'Dim myString As String
'myString =

prm = New SqlParameter("@YearOfManufacture", SqlDbType.DateTime)
prm.Value = yearOfManufacture


End Using
End Using

Return True
Catch ex As Exception

Return (False)
End Try

End Function

End Class

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -


by Shellbot In reply to no data in my database

Can you "step through" this in debug mode and see what is happening? Should be able to spot quick enough.

Been ages since done any of this, but maybe just make sure your executing properly.

Collapse -

Can't see anything obviously wrong with that code wise

by Tony Hopkinson In reply to no data in my database

Suggest you comment out the try catch, swallowing exception like you are is an extremely bad idea.

Can't tell from from the code but something as simple as misname column in the table would give the result you are seeing.

Related Discussions

Related Forums