-
May 13th, 2009, 04:07 AM
#1
Thread Starter
Hyperactive Member
[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.
-
May 13th, 2009, 04:34 AM
#2
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
-
May 13th, 2009, 03:42 PM
#3
Thread Starter
Hyperactive Member
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:
and if "789" it will result to
Thanks and have a nice day.
-
May 14th, 2009, 03:59 AM
#4
Re: How to fill in my gridview
vb Code:
im CSCode As String = = "123456789" 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 '%" & CSCode & "%'" 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()
Please mark you thread resolved using the Thread Tools as shown
-
May 17th, 2009, 12:30 AM
#5
Thread Starter
Hyperactive Member
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.
-
May 19th, 2009, 02:57 AM
#6
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|