Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2008 Problem Insert Data into SQL Server 2005 from VB.NET

$
0
0
I am trying to insert data from VB.NET into SQL Server. I am using Visual Studio 2008 and SQL Server 2005. When I press the submit button, it shows the message "Successfully Added". But I checked database table and all the columns are showing Null. My code is given below.

Code:

Dim gend As String
            gend = ""
            If RBMALE.Checked = True And RBFEMALE.Checked = False Then
                gend = RBMALE.Text
            ElseIf RBFEMALE.Checked = True And RBMALE.Checked = False Then
                gend = RBFEMALE.Text
            End If
            Try
                getConnect()
                Dim query As SqlCommand
                Dim strSQL As String
                strSQL = "INSERT INTO EMPLOYEE (EMP_ID,EMP_NAME,EMP_FNAME,EMP_GENDER,EMP_DOB,EMP_CAST,EMP_DEPART,EMP_DESIG,EMP_DOJ,EMP_SALARY,EMP_PF_ESI,EMP_BRANCH,EMP_CONTACT,EMP_ADDRESS)VALUES(@EMP_ID,@EMP_NAME,@EMP_FNAME,@EMP_GENDER,@EMP_DOB,@EMP_CAST,@EMP_DEPART,@EMP_DESIG,@EMP_DOJ,@EMP_SALARY,@EMP_PF_ESI,@EMP_BRANCH,@EMP_CONTACT,@EMP_ADDRESS)"
                query = New SqlCommand(strSQL, Conn)
                query.Parameters.AddWithValue("@EMP_ID", CDec(TXTEMPID.Text))
                query.Parameters.AddWithValue("@EMP_NAME", TXTNAME.Text.ToString())
                query.Parameters.AddWithValue("@EMP_FNAME", TXTFNAME.Text.ToString())
                query.Parameters.AddWithValue("@EMP_GENDER", gend.ToString())
                query.Parameters.AddWithValue("@EMP_DOB", DTPEMPDOB.Value.ToShortDateString())
                query.Parameters.AddWithValue("@EMP_CAST", TXTCASTE.Text.ToString())
                query.Parameters.AddWithValue("@EMP_DEPART", CMBDEPT.Text.ToString())
                query.Parameters.AddWithValue("@EMP_DESIG", CMBDESIG.Text.ToString())
                query.Parameters.AddWithValue("@EMP_DOJ", DTPEMPDOJ.Value.ToShortDateString())
                query.Parameters.AddWithValue("@EMP_SALARY", CDec(MTXTSAL.Text))
                query.Parameters.AddWithValue("@EMP_PF_ESI", CDec(MTXTPFESI.Text))
                query.Parameters.AddWithValue("@EMP_BRANCH", TXTBRANCH.Text.ToString())
                query.Parameters.AddWithValue("@EMP_CONTACT", CDec(MTXTCONTACT.Text))
                query.Parameters.AddWithValue("@EMP_ADDRESS", RTXTADDRESS.Text.ToString())
                Conn.Open()
                Dim numAffected = query.ExecuteNonQuery()
                'MessageBox.Show(numAffected)
                Conn.Close()
                If numAffected > 0 Then
                    MessageBox.Show("Successfully Added", "Add", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    BTNCLEAR.PerformClick()
                Else
                    MsgBox("No record was inserted")
                End If
            Catch ex As Exception
                MsgBox("ERROR: " + ex.Message, MsgBoxStyle.Information, "Add")
            End Try
        End If

This is my database table

Try check this and give me a solution.
Attached Images
 

Viewing all articles
Browse latest Browse all 27554

Trending Articles



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