Community discussion forum

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

  • 2 months 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 was edited on 03/09/2009 03:13:50 Report abuse

Post a reply

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

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

Want to stay in touch with what's going on? Follow us on twitter!