Results 1 to 9 of 9

Thread: [RESOLVED] how to enter null value ?

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2013
    Posts
    198

    Resolved [RESOLVED] how to enter null value ?

    if textbox is not enabled , a null value must be entered in a database.

    i tried this but there is an error " value of type DBnull cannot be converted to string"

    Code:
    If pretTxt.Enabled = False Then pretTxt.Text = DBNull .value

    and i am trying to do this so that i can insert something like this.

    Code:
     If pretTxt.Enabled = False Then pretTxt.Text = DBNull .value
    
            Dim cmd As New SqlCommand("insert into Marks_master (subject_id, student_id, T_PA_marks, T_ET_marks, P_PA_marks,P_ET_marks) VALUES(@si,@stdid, @tet ,@tpa, @pet, @ppa)", con)
            cmd.Parameters.AddWithValue("si", subjectLbl.Text)
            cmd.Parameters.AddWithValue("stdid", studentidTxt.Text)
            cmd.Parameters.AddWithValue("tet", thetTxt.Text)
            cmd.Parameters.AddWithValue("tpa", thpaTxt.Text)
            cmd.Parameters.AddWithValue("pet", pretTxt.Text)
            cmd.Parameters.AddWithValue("ppa", prpaTxt.Text)
    
           Try
                cmd.ExecuteNonQuery()
                MessageBox.Show("Record added")
            Catch ex As Exception
                MessageBox.Show("Error while adding record")
            End Try
            con.Close()

    if textbox is not enabled then null value must be inserted in the table.
    Last edited by hlsc1983; Feb 2nd, 2016 at 10:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width