Lennie Kuah

Lennie Kuah

  • NA
  • 27
  • 0

VBNET2008 SQL COMMAND PARAMETER

Mar 25 2012 12:23 AM
 Hullo Good Friends,  

I need your help. Please help me.

I am using VBNET2008 Window Application AND SQLSERVER 2000 table.

I was requested to develop an Employee Registration Application and do encounter a problem

With the TextBox Date when using SQL Command  Parameter to insert into the tblEmployee table

This is the error message: TextBox Date is a string

Listed below is the over all coding;

Private Sub FInsertEmployee()

        Dim strsql As String = nothing

            strsql = " Insert into tblEmployees "

            strsql &= "(EmployeeID, LastName, FirstName, Title, HireDate "

             strsql &= " Values (@intEmpID, @LastName, @FirstName, @Title  " @HireDate )  "

         Try

            sqlconn = New SqlConnection(connstr)

            sqlconn.Open()

            sqlcmd = New SqlCommand(strsql, sqlconn)

             With sqlcmd.Parameters

         .AddWithValue("@intEmpID", SqlDbType.Int).Value = Convert.ToInt32(intEmployeeId)

         .AddWithValue("@LastName", SqlDbType.NVarChar).Value = Me.txtLastName.Text.ToString

         .AddWithValue("@FirstName", SqlDbType.NVarChar).Value = Me.txtFirstName.Text.ToString

        .AddWithValue("@Title", SqlDbType.NVarChar).Value = Me.txtTitle.Text.ToString

AddWithValue("@HireDate", SqlDbType.DateTime).Value = DateTime.ParseMe.txtHireDate.Text)            

            End With

             sqlcmd.ExecuteNonQuery()

         Catch ex As Exception

            MessageBox.Show(ex.Message)

         Finally

            sqlconn.Close()

            sqlcmd.Dispose()

         End Try

    End Sub

Thank you very much for helping me.

Cheers,

Lennie Kuah


Answers (1)