Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
 Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            cm2 = New OleDb.OleDbCommand
            With cm2
                .Connection = cn
                .CommandType = CommandType.Text
                .CommandText = "INSERT INTO PatientData (Name, Age, ICNum, Address, Dr_Preffered, PatientID, CheckIn, RoomType, RoomNo) VALUES (@ptNam, @ptAg, @ptIC, @ptAdr, @ptDR, @ptID, @ptChkIn, @ptType, @ptRoom,)"
                .Parameters.Add(New System.Data.OleDb.OleDbParameter("@ptNam", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtName.Text))
                .Parameters.Add(New System.Data.OleDb.OleDbParameter("@ptAg", System.Data.OleDb.OleDbType.Integer, 255, Me.txtAge.Text))
                .Parameters.Add(New System.Data.OleDb.OleDbParameter("@ptIC", System.Data.OleDb.OleDbType.Integer, 255, Me.txtIC.Text))
                .Parameters.Add(New System.Data.OleDb.OleDbParameter("@ptAdr", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtAddress.Text))
                .Parameters.Add(New System.Data.OleDb.OleDbParameter("@ptDR", System.Data.OleDb.OleDbType.VarChar, 255, Me.cmbDoctor.Text.Length))
                .Parameters.Add(New System.Data.OleDb.OleDbParameter("@ptID", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtPtID.Text))
                .Parameters.Add(New System.Data.OleDb.OleDbParameter("@ptChkIn", System.Data.OleDb.OleDbType.DBDate, 255, Me.DateTimePicker1.Value))
                .Parameters.Add(New System.Data.OleDb.OleDbParameter("@ptType", System.Data.OleDb.OleDbType.VarChar, 255, Me.rbIP.Checked = True Or Me.rbOP.Checked = True))
                .Parameters.Add(New System.Data.OleDb.OleDbParameter("@ptRoom", System.Data.OleDb.OleDbType.VarChar, 255, Me.cmbRoom.Text.Length))

                cm2.Parameters("@ptNam").Value = Me.txtName.Text
                cm2.Parameters("@ptAg").Value = Me.txtAge.Text
                cm2.Parameters("@ptIC").Value = Me.txtIC.Text
                cm2.Parameters("@ptAdr").Value = Me.txtAddress.Text
                cm2.Parameters("@ptDR").Value = Me.cmbDoctor.Text.Length
                cm2.Parameters("@ptID").Value = Me.txtPtID.Text
                cm2.Parameters("@ptChkIn").Value = Me.DateTimePicker1.Value
                cm2.Parameters("@ptType").Value = Me.rbIP.Checked = True Or Me.rbOP.Checked = True
                cm2.Parameters("@ptRoom").Value = Me.cmbRoom.Text.Length

                cm2.ExecuteNonQuery()
                MsgBox("Patient Register Successesfully.", MsgBoxStyle.Information)
                Exit Sub
            End With
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

What I have tried:

i thought it is because of datetimepicker..
maybe it's because of my rb
Posted
Updated 24-Dec-17 13:35pm
Comments
Bryian Tan 24-Dec-17 15:14pm    
did you debug and see which line is causing the error?
pt1401 24-Dec-17 16:31pm    
And what are the contents of your textboxes?
I'm guessing that either txtAge or txtIC dont have integers in them?
Nakhia_ind 26-Dec-17 9:49am    
sir two times took the parameter values.if you would like to send the procedure parameters data type details can say.

1 solution

Quote:
i thought it is because of datetimepicker..
maybe it's because of my rb

No, don't think, don't 'maybe', never, it is not a guessing game. Use the debugger to ensure and be safe. There is an English saying: Better safe than sorry.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]
Visual Basic / Visual Studio Video Tutorial - Basic Debugging - YouTube[^]
Visual Basic .NET programming for Beginners - Breakpoints and Debugging Tools[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900