VB.net ms SQL 2005 express :- couldn't enter data into database

vb.net , sql , insert , form , database Singapore, Singapore
  • 8 years ago

    hi there,

    i'm quite new to vb.net and ms sql and been learning by browsing through many online tutorials and guides to complete a system.currently im stuck at the part where user enter data through form and form pass it to database.but it is just not working.there is a patient database with id,nric,name ,dob,address,telephone, dateofregister fields.Can anyone help me to point out where i did mistake in this coding?thank you very much.

    Imports System.Data Imports System.Data.SqlClient

    Public Class Addpatient

    Dim da As New SqlDataAdapter
    
    Dim conn As New SqlConnection(My.Settings.Database1ConnectionString)
    
    
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
    
        conn.Open()
        Try
            Dim strSQL As String
            strSQL = "INSERT INTO patient (id,nric,name,dob,address,telephone,dateofregister) VALUES  (" _
            & "'" & idtxt.Text & "', " _
            & "'" & nrictxt.Text & "', " _
            & "'" & nametxt.Text & "', " _
            & "'" & dobtxt.Text & "', " _
            & "'" & addrtxt.Text & "',  " _
            & "'" & teleptxt.Text & "', " _
            & "'" & datetxt.Text & "')"
    
            da.InsertCommand = New SqlCommand(strSQL, conn)
            da.InsertCommand.ExecuteNonQuery()
    
    
            MessageBox.Show("Record Succesfully added.", "Process Completed", MessageBoxButtons.OK, MessageBoxIcon.Information)
    
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            conn.Close()
            da.Dispose()
    
        End Try
        Me.Close()
    
    End Sub
    
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    
        Mainmenu.Show()
        Me.Hide()
    End Sub
    
    
    
    
    Private Sub Addpatient_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        idtxt.Text = ""
        nrictxt.Text = ""
        nametxt.Text = ""
        dobtxt.Text = ""
        addrtxt.Text = ""
        teleptxt.Text = ""
        datetxt.Text = ""
    
    End Sub
    

    End Class

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook