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 I search DataGridView with text column?

How I search DataGridView with text column?

Scheduled Pinned Locked Moved Visual Basic
databasehelpsql-serversysadminquestion
8 Posts 4 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.
  • C Offline
    C Offline
    Curious 2009
    wrote on last edited by
    #1

    I had mistake to define my SQL Server database table with all columns with TEXT, with my DataGridView the following codes are working fine (it will show every thing with its randome order):

       cmd = New SqlCommand("SELECT \* FROM GuestInfoStore", con)
    
        If con.State = ConnectionState.Closed Then con.Open()
    
        myDA = New SqlDataAdapter(cmd)
        myDataSet = New DataSet()
        myDA.Fill(myDataSet, "MyTable")
    
        DataGridView\_INFO.DataSource = myDataSet.Tables("MyTable").DefaultView
    

    In my table, there is a column FirstName, if I use:

    cmd = New SqlCommand("SELECT * FROM GuestInfoStore ORDER BY FirstName", con)

    I will have an error since SQL can't compare with Text column, but it is too late for me to change FirstName column back to char(50) or so ... can anyone help me on this? Thank in-advanced :doh:

    L 1 Reply Last reply
    0
    • C Curious 2009

      I had mistake to define my SQL Server database table with all columns with TEXT, with my DataGridView the following codes are working fine (it will show every thing with its randome order):

         cmd = New SqlCommand("SELECT \* FROM GuestInfoStore", con)
      
          If con.State = ConnectionState.Closed Then con.Open()
      
          myDA = New SqlDataAdapter(cmd)
          myDataSet = New DataSet()
          myDA.Fill(myDataSet, "MyTable")
      
          DataGridView\_INFO.DataSource = myDataSet.Tables("MyTable").DefaultView
      

      In my table, there is a column FirstName, if I use:

      cmd = New SqlCommand("SELECT * FROM GuestInfoStore ORDER BY FirstName", con)

      I will have an error since SQL can't compare with Text column, but it is too late for me to change FirstName column back to char(50) or so ... can anyone help me on this? Thank in-advanced :doh:

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Curious 2009 wrote:

      it is too late for me to change FirstName column back to char(50)

      it is never too late to fix a mistake. Things can only get worse if you don't. You could: - add a field with the correct type; - automatically copy the existing field to the new one; - gradually adapt your software, first the field producers (methods that write the field): make them write both fields; then the field consumers (the methods that read the field): make them read the new field. - when all is done, remove the redundant field. The alternative is a lot of ugly code, that will grow and grow over time, as you keep adding features. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read formatted code with indentation, so please use PRE tags for code snippets.


      I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


      C E 2 Replies Last reply
      0
      • L Luc Pattyn

        Curious 2009 wrote:

        it is too late for me to change FirstName column back to char(50)

        it is never too late to fix a mistake. Things can only get worse if you don't. You could: - add a field with the correct type; - automatically copy the existing field to the new one; - gradually adapt your software, first the field producers (methods that write the field): make them write both fields; then the field consumers (the methods that read the field): make them read the new field. - when all is done, remove the redundant field. The alternative is a lot of ugly code, that will grow and grow over time, as you keep adding features. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read formatted code with indentation, so please use PRE tags for code snippets.


        I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


        C Offline
        C Offline
        Curious 2009
        wrote on last edited by
        #3

        You are right & I will do as you suggested! Thank :)

        L 1 Reply Last reply
        0
        • C Curious 2009

          You are right & I will do as you suggested! Thank :)

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Good. If it is a simple TEXT->VARCHAR change, I think you can tell SQL Server to do that in place, in a single step. I haven't so far, I have done similar things with MySQL. It is trickier when more complex formatting is involved, such as string->DateTime. It is always safe to make an extra field as a backup! :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read formatted code with indentation, so please use PRE tags for code snippets.


          I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


          C 1 Reply Last reply
          0
          • L Luc Pattyn

            Good. If it is a simple TEXT->VARCHAR change, I think you can tell SQL Server to do that in place, in a single step. I haven't so far, I have done similar things with MySQL. It is trickier when more complex formatting is involved, such as string->DateTime. It is always safe to make an extra field as a backup! :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read formatted code with indentation, so please use PRE tags for code snippets.


            I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


            C Offline
            C Offline
            Curious 2009
            wrote on last edited by
            #5

            I did copy & it works, I will try to find the command for simple TEXT->VARCHAR change Thank again

            L 1 Reply Last reply
            0
            • C Curious 2009

              I did copy & it works, I will try to find the command for simple TEXT->VARCHAR change Thank again

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              There is a management tool SSMS, that should be able to do such operations interactively. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read formatted code with indentation, so please use PRE tags for code snippets.


              I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


              1 Reply Last reply
              0
              • L Luc Pattyn

                Curious 2009 wrote:

                it is too late for me to change FirstName column back to char(50)

                it is never too late to fix a mistake. Things can only get worse if you don't. You could: - add a field with the correct type; - automatically copy the existing field to the new one; - gradually adapt your software, first the field producers (methods that write the field): make them write both fields; then the field consumers (the methods that read the field): make them read the new field. - when all is done, remove the redundant field. The alternative is a lot of ugly code, that will grow and grow over time, as you keep adding features. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read formatted code with indentation, so please use PRE tags for code snippets.


                I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                E Offline
                E Offline
                elizas
                wrote on last edited by
                #7

                Following is the code sample used to display the outlook folder dialog using VB.NET [VB.NET CODE STARTS] Dim objOutlook As Object Dim objOlNamespace As Object Dim objOlFolder As Object objOutlook = CreateObject("Outlook.Application") ' create outlook application object at the run time objOlNamespace = objOutlook.GetNamespace("MAPI") objOlFolder = objContactsNS.PickFolder ' displays the folder dialog [VB.NET CODE ENDS] http://www.mindfiresolutions.com/Open-Outlook-folder-dialog-and-select-folder-using-VBNET-896.php[^]

                Cheers, Eliza

                D 1 Reply Last reply
                0
                • E elizas

                  Following is the code sample used to display the outlook folder dialog using VB.NET [VB.NET CODE STARTS] Dim objOutlook As Object Dim objOlNamespace As Object Dim objOlFolder As Object objOutlook = CreateObject("Outlook.Application") ' create outlook application object at the run time objOlNamespace = objOutlook.GetNamespace("MAPI") objOlFolder = objContactsNS.PickFolder ' displays the folder dialog [VB.NET CODE ENDS] http://www.mindfiresolutions.com/Open-Outlook-folder-dialog-and-select-folder-using-VBNET-896.php[^]

                  Cheers, Eliza

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Garbage. Utter garbage. And it doesn't have anything to do with the original posters problem.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007, 2008
                  But no longer in 2009...

                  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