Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6360955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:42:53+00:00 2026-05-24T23:42:53+00:00

No idea why this isn’t working. I have a simple form with some text

  • 0

No idea why this isn’t working.

I have a simple form with some text boxes and drop down lists. It displays the profile of an employee. Users should be able to manually edit the fields and click Save. When they click save I keep getting errors.

Q1: How can I handle inserting Null values for SmallDateTime data types?

Q2: What am I doing wrong with the TinyInt (SqlServer 2005) on the JobGrade?

Option Explicit On 
Imports System 
Imports System.Data 
Imports System.Data.SqlClient 

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click

    Dim sqlJobsDB As New SqlConnection(ConfigurationManager.ConnectionStrings("JobsDB").ConnectionString)
    Dim sqlCmdUpdate As SqlCommand = sqlJobsDB.CreateCommand()

    Try

        sqlJobsDB.Open()
        sqlCmdUpdate.CommandText = _
            "UPDATE tblEmployee " + _
             "SET Firstname = @Firstname, LastName = @LastName, HiredLastName = @HiredLastName, " + _
                "DateHired = @DateHired, Role = @Role, CADate = @CADate, CAType = @CAType, " + _
                "JobDate = @JobDate, JobGrade = @JobGrade " + _
             "WHERE EUID = '" & Session("sProfileEUID") & "';"

        sqlCmdUpdate.Parameters.Add("@FirstName", SqlDbType.VarChar)
        sqlCmdUpdate.Parameters.Add("@LastName", SqlDbType.VarChar)
        sqlCmdUpdate.Parameters.Add("@HiredLastName", SqlDbType.VarChar)
        sqlCmdUpdate.Parameters.Add("@DateHired", SqlDbType.SmallDateTime)
        sqlCmdUpdate.Parameters.Add("@Role", SqlDbType.VarChar)
        sqlCmdUpdate.Parameters.Add("@CADate", SqlDbType.SmallDateTime)
        sqlCmdUpdate.Parameters.Add("@CAType", SqlDbType.VarChar)
        sqlCmdUpdate.Parameters.Add("@JobDate", SqlDbType.SmallDateTime)
        sqlCmdUpdate.Parameters.Add("@JobGrade", SqlDbType.TinyInt)

        sqlCmdUpdate.Parameters("@FirstName").Value = txtFirstName.Text
        sqlCmdUpdate.Parameters("@LastName").Value = txtLastName.Text
        sqlCmdUpdate.Parameters("@HiredLastName").Value = txtHiredLastName.Text
        sqlCmdUpdate.Parameters("@DateHired").Value = txtDateHired.Text
        sqlCmdUpdate.Parameters("@Role").Value = ddlRole.SelectedValue.ToString

        If txtCADate.Text = "" Then
            sqlCmdUpdate.Parameters("@CADate").Value = 0
        Else
            sqlCmdUpdate.Parameters("@CADate").Value = txtCADate.Text
        End If

        sqlCmdUpdate.Parameters("@CAType").Value = ddlCAType.SelectedValue

        If txtJobDate.Text = "" Then
            sqlCmdUpdate.Parameters("@JobDate").Value = 0
        Else
            sqlCmdUpdate.Parameters("@JobDate").Value = txtJobDate.Text
        End If

        sqlCmdUpdate.Parameters("@JobGrade").Value = CByte(txtJobGrade.Text)

        sqlCmdUpdate.ExecuteNonQuery()

    Catch ex As Exception

        'Debugging
        lblErrMsg.Text = ex.ToString
        lblErrMsg.Visible = True

    Finally

        sqlJobsDB.Close()

    End Try

End Sub</code>

I open the form and fill it out correctly.
I'll enter something like "4" (no quotes) for JobGrade. It still says "conversion from strink ''" like its not even seeing when I input items on the form.

Errors are below:

System.InvalidCastException: Conversion from string "" to type 'Byte' is not valid. ---> System.FormatException: Input string was not in a correct format. at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToByte(String Value) --- End of inner exception stack trace --- at Microsoft.VisualBasic.CompilerServices.Conversions.ToByte(String Value) at Profile.btnSave_Click(Object sender, EventArgs e) in

Update

The DBNull.Value issue is resolved.
The JobGrade, and Role are still issues. When throwing up some breakpoints on it doens't fetch the contents of the textbox or the dropdown list.

** Updated Code **

Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click

    Session("sProfileEUID") = Nothing
    Response.Redirect("~/Management/EditUsers.aspx")

End Sub

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click

    Dim sqlJobsDB As New SqlConnection(ConfigurationManager.ConnectionStrings("JobsDB").ConnectionString)
    Dim sqlCmdUpdate As SqlCommand = sqlJobsDB.CreateCommand()

    Try

        sqlJobsDB.Open()
        sqlCmdUpdate.CommandText = _
            "UPDATE tblEmployee " + _
             "SET FirstName = @FirstName, LastName = @LastName, HiredLastName = @HiredLastName, " + _
                "DateHired = @DateHired, Role = @Role, CADate = @CADate, CAType = @CAType, " + _
                "JobDate = @JobDate, JobGrade = @JobGrade " + _
             "WHERE EUID = '" & Session("sProfileEUID") & "';"

        sqlCmdUpdate.Parameters.Add("@FirstName", SqlDbType.VarChar)
        sqlCmdUpdate.Parameters.Add("@LastName", SqlDbType.VarChar)
        sqlCmdUpdate.Parameters.Add("@HiredLastName", SqlDbType.VarChar)
        sqlCmdUpdate.Parameters.Add("@DateHired", SqlDbType.SmallDateTime)
        sqlCmdUpdate.Parameters.Add("@Role", SqlDbType.VarChar)
        sqlCmdUpdate.Parameters.Add("@CADate", SqlDbType.SmallDateTime)
        sqlCmdUpdate.Parameters.Add("@CAType", SqlDbType.VarChar)
        sqlCmdUpdate.Parameters.Add("@JobDate", SqlDbType.SmallDateTime)
        sqlCmdUpdate.Parameters.Add("@JobGrade", SqlDbType.TinyInt)

        sqlCmdUpdate.Parameters("@FirstName").Value = txtFirstName.Text
        sqlCmdUpdate.Parameters("@LastName").Value = txtLastName.Text
        sqlCmdUpdate.Parameters("@HiredLastName").Value = txtHiredLastName.Text
        sqlCmdUpdate.Parameters("@DateHired").Value = txtDateHired.Text
        sqlCmdUpdate.Parameters("@Role").Value = ddlRole.SelectedValue.ToString

        If txtCADate.Text <> "" Then sqlCmdUpdate.Parameters("@CADate").Value = CDate(txtCADate.Text)
        If txtCADate.Text = "" Then sqlCmdUpdate.Parameters("@CADate").Value = DBNull.Value

        If ddlCAType.Text <> "" Then sqlCmdUpdate.Parameters("@CAType").Value = ddlCAType.SelectedValue
        If ddlCAType.Text = "" Then sqlCmdUpdate.Parameters("@CAType").Value = DBNull.Value

        If txtJobDate.Text <> "" Then sqlCmdUpdate.Parameters("@JobDate").Value = CDate(txtJobDate.Text)
        If txtJobDate.Text = "" Then sqlCmdUpdate.Parameters("@JobDate").Value = DBNull.Value

        If txtJobGrade.Text <> "" Then sqlCmdUpdate.Parameters("@JobGrade").Value = CInt(txtJobGrade.Text)
        If txtJobGrade.Text = "" Then sqlCmdUpdate.Parameters("@JobGrade").Value = DBNull.Value

        sqlCmdUpdate.ExecuteNonQuery()

    Catch ex As Exception

        lblErrMsg.Text = ex.ToString
        lblErrMsg.Visible = True

    Finally

        sqlJobsDB.Close()

    End Try

End Sub

Edit 2:

So I've pretty much given up on this, and instead moved the table into an FormView ItemTemplate, with an EditTemplate also. I modified it as described in the following link. http://www.beansoftware.com/ASP.NET-Tutorials/FormView-Control.aspx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:42:53+00:00Added an answer on May 24, 2026 at 11:42 pm

    Q1: Make sure the table structure allows nulls and set the parameter value to DBNull.Value.

    Q2:

    If IsNumeric(txtJobGrade.Text) Then
    
    sqlCmdUpdate.Parameters("@JobGrade").Value = CInt(txtJobGrade.Text) 
    
    Else
    
    sqlCmdUpdate.Parameters("@JobGrade").Value = 0 'Or Default Value
    
    End If
    

    You can always make that a drop down list to prevent open ended data input.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have no idea why this isn't working. I've taken code from a previous
Anyone have any idea why this isn't working? $(function(){ console.log('ready'); $.ajax({ dataType : 'jsonp',
Anybody have any idea why this query isn't working? $result = mysql_query(SELECT * FROM
I have no idea why this isn't working. NSData *data = [NSData dataWithContentsOfURL:place.iconData]; UIImage
I have no idea why this isn't working, but I can't seem to get
I have no idea why this is happening. I have some very straightforward code,
I have no idea why this doesn't work, but doing some validation functions and
Been awhile since I've used structs in C++. Any idea why this isn't working?
Any idea why this accordion isn't working correctly? Only the clicked division should open/close
For whatever reason, this little piece of dojo isn't working. I have to admit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.