Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to insert all characters in database

How to insert all characters in database

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasetutorialquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Beiniam
    wrote on last edited by
    #1

    hello guys i have doing some project and since i have new for vb.net 2010. my project is coded in vb.net 2010 and ms access 2007 mdb database. i have DocId, description, date and other fileds in the table.. my querry works for all but. i can't add all characters except integers in the database column DocId. it accepts only integer values. so how can i insert characters in the DocId filed. here is the detail tables: DocId======Textbox name RefferencNoTxt.Text Table name = EraDms database name= data

    cmd.CommandText = "INSERT INTO EraDms(DocId,Description,Address,NoOfPages, SendOrReceived, SentDate,ReceivedDate,ForwardedWorkingUnit,Attachements,ForwardedDate,ReceivedBy,DocPath) " & _
    " VALUES(" & Me.RefferencNoTxt.Text.ToString & ",'" & Me.DescriptionTextBox.Text & "','" & Me.AddressTextBox.Text & "','" & Me.NoOfPagesTextBox.Text & "','" & Me.SendOrReceievedComboBox.Text & "','" & _
    Me.SentDateTextBox.Text & "','" & Me.receivedDate.Text & "','" & Me.ForwardedWorkingUnitTextBox.Text & "','" & Me.AttachementsTextBox.Text & "','" & Me.TextBox6.Text & "','" & Me.ReceivedByTextBox.Text & "','" & Me.DocPathTextBox.Text & "')"
    cmd.ExecuteNonQuery()
    MessageBox.Show("File Upload Successfull", "ERA-DMS-File Uploader", MessageBoxButtons.OK, MessageBoxIcon.Information)
    RefreshData()

           '  With ERA\_DMS\_HOME
    
           ' End With
           cnn.Close()
       Else
           'update data in table
           cmd.CommandText = "UPDATE Eradms " & \_
                       " SET DocId=" & Me.RefferencNoTxt.Text.ToString & \_
                       ", Description='" & Me.DescriptionTextBox.Text & "'" & \_
                       ", Address='" & Me.AddressTextBox.Text & "'" & \_
                       ", NoOfPages='" & Me.NoOfPagesTextBox.Text & "'" & \_
                       ", SendOrReceived='" & Me.SendOrReceievedComboBox.Text & "'" & \_
    
    B L S Richard DeemingR 4 Replies Last reply
    0
    • B Beiniam

      hello guys i have doing some project and since i have new for vb.net 2010. my project is coded in vb.net 2010 and ms access 2007 mdb database. i have DocId, description, date and other fileds in the table.. my querry works for all but. i can't add all characters except integers in the database column DocId. it accepts only integer values. so how can i insert characters in the DocId filed. here is the detail tables: DocId======Textbox name RefferencNoTxt.Text Table name = EraDms database name= data

      cmd.CommandText = "INSERT INTO EraDms(DocId,Description,Address,NoOfPages, SendOrReceived, SentDate,ReceivedDate,ForwardedWorkingUnit,Attachements,ForwardedDate,ReceivedBy,DocPath) " & _
      " VALUES(" & Me.RefferencNoTxt.Text.ToString & ",'" & Me.DescriptionTextBox.Text & "','" & Me.AddressTextBox.Text & "','" & Me.NoOfPagesTextBox.Text & "','" & Me.SendOrReceievedComboBox.Text & "','" & _
      Me.SentDateTextBox.Text & "','" & Me.receivedDate.Text & "','" & Me.ForwardedWorkingUnitTextBox.Text & "','" & Me.AttachementsTextBox.Text & "','" & Me.TextBox6.Text & "','" & Me.ReceivedByTextBox.Text & "','" & Me.DocPathTextBox.Text & "')"
      cmd.ExecuteNonQuery()
      MessageBox.Show("File Upload Successfull", "ERA-DMS-File Uploader", MessageBoxButtons.OK, MessageBoxIcon.Information)
      RefreshData()

             '  With ERA\_DMS\_HOME
      
             ' End With
             cnn.Close()
         Else
             'update data in table
             cmd.CommandText = "UPDATE Eradms " & \_
                         " SET DocId=" & Me.RefferencNoTxt.Text.ToString & \_
                         ", Description='" & Me.DescriptionTextBox.Text & "'" & \_
                         ", Address='" & Me.AddressTextBox.Text & "'" & \_
                         ", NoOfPages='" & Me.NoOfPagesTextBox.Text & "'" & \_
                         ", SendOrReceived='" & Me.SendOrReceievedComboBox.Text & "'" & \_
      
      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      Change the definition of DocID from Integer to Text in the database.

      B 1 Reply Last reply
      0
      • B Bernhard Hiller

        Change the definition of DocID from Integer to Text in the database.

        B Offline
        B Offline
        Beiniam
        wrote on last edited by
        #3

        DocId data type is text in my database

        1 Reply Last reply
        0
        • B Beiniam

          hello guys i have doing some project and since i have new for vb.net 2010. my project is coded in vb.net 2010 and ms access 2007 mdb database. i have DocId, description, date and other fileds in the table.. my querry works for all but. i can't add all characters except integers in the database column DocId. it accepts only integer values. so how can i insert characters in the DocId filed. here is the detail tables: DocId======Textbox name RefferencNoTxt.Text Table name = EraDms database name= data

          cmd.CommandText = "INSERT INTO EraDms(DocId,Description,Address,NoOfPages, SendOrReceived, SentDate,ReceivedDate,ForwardedWorkingUnit,Attachements,ForwardedDate,ReceivedBy,DocPath) " & _
          " VALUES(" & Me.RefferencNoTxt.Text.ToString & ",'" & Me.DescriptionTextBox.Text & "','" & Me.AddressTextBox.Text & "','" & Me.NoOfPagesTextBox.Text & "','" & Me.SendOrReceievedComboBox.Text & "','" & _
          Me.SentDateTextBox.Text & "','" & Me.receivedDate.Text & "','" & Me.ForwardedWorkingUnitTextBox.Text & "','" & Me.AttachementsTextBox.Text & "','" & Me.TextBox6.Text & "','" & Me.ReceivedByTextBox.Text & "','" & Me.DocPathTextBox.Text & "')"
          cmd.ExecuteNonQuery()
          MessageBox.Show("File Upload Successfull", "ERA-DMS-File Uploader", MessageBoxButtons.OK, MessageBoxIcon.Information)
          RefreshData()

                 '  With ERA\_DMS\_HOME
          
                 ' End With
                 cnn.Close()
             Else
                 'update data in table
                 cmd.CommandText = "UPDATE Eradms " & \_
                             " SET DocId=" & Me.RefferencNoTxt.Text.ToString & \_
                             ", Description='" & Me.DescriptionTextBox.Text & "'" & \_
                             ", Address='" & Me.AddressTextBox.Text & "'" & \_
                             ", NoOfPages='" & Me.NoOfPagesTextBox.Text & "'" & \_
                             ", SendOrReceived='" & Me.SendOrReceievedComboBox.Text & "'" & \_
          
          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          What is the actual definition for DocId in your database schema? Also why are you calling ToString on the Me.RefferencNoTxt.Text object; is it not already text?

          Use the best guess

          1 Reply Last reply
          0
          • B Beiniam

            hello guys i have doing some project and since i have new for vb.net 2010. my project is coded in vb.net 2010 and ms access 2007 mdb database. i have DocId, description, date and other fileds in the table.. my querry works for all but. i can't add all characters except integers in the database column DocId. it accepts only integer values. so how can i insert characters in the DocId filed. here is the detail tables: DocId======Textbox name RefferencNoTxt.Text Table name = EraDms database name= data

            cmd.CommandText = "INSERT INTO EraDms(DocId,Description,Address,NoOfPages, SendOrReceived, SentDate,ReceivedDate,ForwardedWorkingUnit,Attachements,ForwardedDate,ReceivedBy,DocPath) " & _
            " VALUES(" & Me.RefferencNoTxt.Text.ToString & ",'" & Me.DescriptionTextBox.Text & "','" & Me.AddressTextBox.Text & "','" & Me.NoOfPagesTextBox.Text & "','" & Me.SendOrReceievedComboBox.Text & "','" & _
            Me.SentDateTextBox.Text & "','" & Me.receivedDate.Text & "','" & Me.ForwardedWorkingUnitTextBox.Text & "','" & Me.AttachementsTextBox.Text & "','" & Me.TextBox6.Text & "','" & Me.ReceivedByTextBox.Text & "','" & Me.DocPathTextBox.Text & "')"
            cmd.ExecuteNonQuery()
            MessageBox.Show("File Upload Successfull", "ERA-DMS-File Uploader", MessageBoxButtons.OK, MessageBoxIcon.Information)
            RefreshData()

                   '  With ERA\_DMS\_HOME
            
                   ' End With
                   cnn.Close()
               Else
                   'update data in table
                   cmd.CommandText = "UPDATE Eradms " & \_
                               " SET DocId=" & Me.RefferencNoTxt.Text.ToString & \_
                               ", Description='" & Me.DescriptionTextBox.Text & "'" & \_
                               ", Address='" & Me.AddressTextBox.Text & "'" & \_
                               ", NoOfPages='" & Me.NoOfPagesTextBox.Text & "'" & \_
                               ", SendOrReceived='" & Me.SendOrReceievedComboBox.Text & "'" & \_
            
            S Offline
            S Offline
            Simon_Whale
            wrote on last edited by
            #5

            Beiniam wrote:

            i can't add all characters except integers in the database column DocId. it accepts only integer values. so how can i insert characters in the DocId filed.

            From that it makes me ask the question is the column type numeric? (integer, decimal etc.) you will need to convert RefferencNoTxt.Text to the correct numeric type that your database needs. i.e.

            dim value as integer = Convert.ToInt32(RefferencNoTxt.Text)

            Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

            1 Reply Last reply
            0
            • B Beiniam

              hello guys i have doing some project and since i have new for vb.net 2010. my project is coded in vb.net 2010 and ms access 2007 mdb database. i have DocId, description, date and other fileds in the table.. my querry works for all but. i can't add all characters except integers in the database column DocId. it accepts only integer values. so how can i insert characters in the DocId filed. here is the detail tables: DocId======Textbox name RefferencNoTxt.Text Table name = EraDms database name= data

              cmd.CommandText = "INSERT INTO EraDms(DocId,Description,Address,NoOfPages, SendOrReceived, SentDate,ReceivedDate,ForwardedWorkingUnit,Attachements,ForwardedDate,ReceivedBy,DocPath) " & _
              " VALUES(" & Me.RefferencNoTxt.Text.ToString & ",'" & Me.DescriptionTextBox.Text & "','" & Me.AddressTextBox.Text & "','" & Me.NoOfPagesTextBox.Text & "','" & Me.SendOrReceievedComboBox.Text & "','" & _
              Me.SentDateTextBox.Text & "','" & Me.receivedDate.Text & "','" & Me.ForwardedWorkingUnitTextBox.Text & "','" & Me.AttachementsTextBox.Text & "','" & Me.TextBox6.Text & "','" & Me.ReceivedByTextBox.Text & "','" & Me.DocPathTextBox.Text & "')"
              cmd.ExecuteNonQuery()
              MessageBox.Show("File Upload Successfull", "ERA-DMS-File Uploader", MessageBoxButtons.OK, MessageBoxIcon.Information)
              RefreshData()

                     '  With ERA\_DMS\_HOME
              
                     ' End With
                     cnn.Close()
                 Else
                     'update data in table
                     cmd.CommandText = "UPDATE Eradms " & \_
                                 " SET DocId=" & Me.RefferencNoTxt.Text.ToString & \_
                                 ", Description='" & Me.DescriptionTextBox.Text & "'" & \_
                                 ", Address='" & Me.AddressTextBox.Text & "'" & \_
                                 ", NoOfPages='" & Me.NoOfPagesTextBox.Text & "'" & \_
                                 ", SendOrReceived='" & Me.SendOrReceievedComboBox.Text & "'" & \_
              
              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              Your code is a classic example of SQL Injection[^]. One mis-placed ' in a text box, and your entire database could be corrupted. Change the code to use parametereized queries instead:

              cmd.CommandText = _
              "INSERT INTO EraDms(DocId, Description, Address, NoOfPages, SendOrReceived, SentDate, ReceivedDate, ForwardedWorkingUnit, Attachements, ForwardedDate, ReceivedBy, DocPath) " & _
              " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

              ' Parameter names don't matter; OleDbCommand uses positional parameters:
              cmd.Parameters.AddWithValue("@p0", Me.RefferencNoTxt.Text)
              cmd.Parameters.AddWithValue("@p1", Me.DescriptionTextBox.Text)
              cmd.Parameters.AddWithValue("@p2", Me.AddressTextBox.Text)
              cmd.Parameters.AddWithValue("@p3", Me.NoOfPagesTextBox.Text)
              cmd.Parameters.AddWithValue("@p4", Me.SendOrReceievedComboBox.Text)
              cmd.Parameters.AddWithValue("@p5", Me.SentDateTextBox.Text)
              cmd.Parameters.AddWithValue("@p6", Me.receivedDate.Text)
              cmd.Parameters.AddWithValue("@p7", Me.ForwardedWorkingUnitTextBox.Text)
              cmd.Parameters.AddWithValue("@p8", Me.AttachementsTextBox.Text)
              cmd.Parameters.AddWithValue("@p9", Me.TextBox6.Text)
              cmd.Parameters.AddWithValue("@p10", Me.ReceivedByTextBox.Text)
              cmd.Parameters.AddWithValue("@p11", Me.DocPathTextBox.Text)

              And:

              cmd.CommandText = _
              "UPDATE Eradms " & _
              " SET Description = ?, " & _
              " Address = ?, " & _
              " NoOfPages = ?, " & _
              " SendOrReceived = ?, " & _
              " SentDate = ?, " & _
              " ReceivedDate = ?, " & _
              " ForwardedWorkingUnit = ?, " & _
              " Attachements = ?, " & _
              " ForwardedDate = ?, " & _
              " ReceivedBy = ?, " & _
              " DocPath = ? " & _
              " WHERE DocId = ?"

              ' Parameter names don't matter; OleDbCommand uses positional parameters:
              cmd.Parameters.AddWithValue("@p0", Me.DescriptionTextBox.Text)
              cmd.Parameters.AddWithValue("@p1", Me.AddressTextBox.Text)
              cmd.Parameters.AddWithValue("@p2", Me.NoOfPagesTextBox.Text)
              cmd.Parameters.AddWithValue("@p3", Me

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              B 1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                Your code is a classic example of SQL Injection[^]. One mis-placed ' in a text box, and your entire database could be corrupted. Change the code to use parametereized queries instead:

                cmd.CommandText = _
                "INSERT INTO EraDms(DocId, Description, Address, NoOfPages, SendOrReceived, SentDate, ReceivedDate, ForwardedWorkingUnit, Attachements, ForwardedDate, ReceivedBy, DocPath) " & _
                " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

                ' Parameter names don't matter; OleDbCommand uses positional parameters:
                cmd.Parameters.AddWithValue("@p0", Me.RefferencNoTxt.Text)
                cmd.Parameters.AddWithValue("@p1", Me.DescriptionTextBox.Text)
                cmd.Parameters.AddWithValue("@p2", Me.AddressTextBox.Text)
                cmd.Parameters.AddWithValue("@p3", Me.NoOfPagesTextBox.Text)
                cmd.Parameters.AddWithValue("@p4", Me.SendOrReceievedComboBox.Text)
                cmd.Parameters.AddWithValue("@p5", Me.SentDateTextBox.Text)
                cmd.Parameters.AddWithValue("@p6", Me.receivedDate.Text)
                cmd.Parameters.AddWithValue("@p7", Me.ForwardedWorkingUnitTextBox.Text)
                cmd.Parameters.AddWithValue("@p8", Me.AttachementsTextBox.Text)
                cmd.Parameters.AddWithValue("@p9", Me.TextBox6.Text)
                cmd.Parameters.AddWithValue("@p10", Me.ReceivedByTextBox.Text)
                cmd.Parameters.AddWithValue("@p11", Me.DocPathTextBox.Text)

                And:

                cmd.CommandText = _
                "UPDATE Eradms " & _
                " SET Description = ?, " & _
                " Address = ?, " & _
                " NoOfPages = ?, " & _
                " SendOrReceived = ?, " & _
                " SentDate = ?, " & _
                " ReceivedDate = ?, " & _
                " ForwardedWorkingUnit = ?, " & _
                " Attachements = ?, " & _
                " ForwardedDate = ?, " & _
                " ReceivedBy = ?, " & _
                " DocPath = ? " & _
                " WHERE DocId = ?"

                ' Parameter names don't matter; OleDbCommand uses positional parameters:
                cmd.Parameters.AddWithValue("@p0", Me.DescriptionTextBox.Text)
                cmd.Parameters.AddWithValue("@p1", Me.AddressTextBox.Text)
                cmd.Parameters.AddWithValue("@p2", Me.NoOfPagesTextBox.Text)
                cmd.Parameters.AddWithValue("@p3", Me

                B Offline
                B Offline
                Beiniam
                wrote on last edited by
                #7

                thank you a lot

                Richard Deeming

                eming for your help. it works

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups