PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2005 [RESOLVED] How to fill in my gridview-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] How to fill in my gridview

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Resolved [RESOLVED] How to fill in my gridview

    Hello everyone, I have here a code but my problem is that how can i add the value of the result in my gridview. Actually when I put msgbox to the "myString" it result 3 by 3 and that's what i want but the problem is that how can i call all of those strings to display on one column of gridview and each value from my database is beside them? Could anyone help me this? This is my code:


    Code:
      
    
    Dim CSCode As String = = "123456789"
    
    Dim myString As String 
                         
     For z As Integer = 0 To CSCode.Length - 1 Step 3
    
                    myString = CSCode.Substring(z, 3)
                    
    
    
                    Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("database\myData.mdb") & ";")
    
                    Dim strSQL As String
                    strSQL = "SELECT Classification FROM Classification WHERE ClassCode LIKE '" & myString & "'"
    
    
                  
                    Dim objCmd As New OleDbCommand(strSQL, objConn)
                    Dim objDA As New OleDbDataAdapter()
                    objDA.SelectCommand = objCmd
    
                    objConn.Open()
    
    
    
                    Dim objDS As DataSet = New DataSet()
                    objDA.Fill(objDS, "Classification")
    
    
                    ClassGrid.DataSource = objDS
    
                    ClassGrid.DataBind()
    
    
                    objConn.Close()
    
                Next
    Thanks in advance.
    Last edited by shyguyjeff; May 13th, 2009 at 04:46 AM.

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,834

    Re: How to fill in my gridview

    What is the data column type of ClassCode ?
    Please mark you thread resolved using the Thread Tools as shown



    www.techreceipe.tk


  3. #3

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: How to fill in my gridview

    Integer...I just want to fill in like this and the data has specified value on the database. This is what I want as a result on my datagrid.
    Code:
    123     Steel
    456     Pipes
    789     Metal
    I want also to get that in vice versa, like for example


    Code:
    jeff   123789
    james  456789
    john   456
    So if somebody search "456" it will display like this:

    Code:
    james 
    john
    and if "789" it will result to

    Code:
    
    jeff 
    james
    Thanks and have a nice day.

  4. #4
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,834

    Re: How to fill in my gridview

    vb Code:
    1. im CSCode As String = = "123456789"
    2.  
    3.                
    4.  
    5.  
    6.                 Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("database\myData.mdb") & ";")
    7.  
    8.                 Dim strSQL As String
    9.                 strSQL = "SELECT Classification FROM Classification WHERE ClassCode LIKE '%" & CSCode & "%'"
    10.  
    11.  
    12.              
    13.                 Dim objCmd As New OleDbCommand(strSQL, objConn)
    14.                 Dim objDA As New OleDbDataAdapter()
    15.                 objDA.SelectCommand = objCmd
    16.  
    17.                 objConn.Open()
    18.  
    19.  
    20.  
    21.                 Dim objDS As DataSet = New DataSet()
    22.                 objDA.Fill(objDS, "Classification")
    23.  
    24.  
    25.                 ClassGrid.DataSource = objDS
    26.  
    27.                 ClassGrid.DataBind()
    28.  
    29.  
    30.                 objConn.Close()
    Please mark you thread resolved using the Thread Tools as shown



    www.techreceipe.tk


  5. #5

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: How to fill in my gridview

    not that one..The string was arranged orderly and get each value of it. It was split 3 by 3 every 3 character there is a specific value in my table.

  6. #6

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: How to fill in my gridview

    I solved it..What i made is that

    I split the string and get 3 separate values from it, and I create a comma-separated string with those values.

    Code:
    For z As Integer = 0 To CSCode.Length - 1 Step 3
         myString &= "'" & CSCode.Substring(z, 3) & "'"
         If z < CSCode.Length - 4 Then myString &= ","
    Next

    Then I use the IN operator in your SQL:

    SELECT Classification FROM Classification WHERE ClassCode IN(" & myString & ")


    Thanks for the effort everyone. Have a nice day and God Bless..

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width