|
-
Aug 19th, 2007, 06:57 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Search From The Database
Hi, I'm trying to make a program that will identify any file extension but I'm blocked here, I made the database with MS Access 2003 in 2000 format but then when the identify button is clicked i wasn't able to make it search from the database and show the result, can someone give me some help to make it work?
thanks
-
Aug 19th, 2007, 07:04 AM
#2
-
Aug 19th, 2007, 07:11 AM
#3
Thread Starter
Frenzied Member
Re: Search From The Database
i didn't write any code, normally i use this code on vb.net but now on vb6 i don't know where to start.
vb Code:
Private Sub butOk_Click(ByValsender As System.Object, ByVal e As System.EventArgs) Handles but_ok.Click
Dim strConnection As String = "Data Source=your SQL data source;Initial Catalog=your database; Integrated Security=True"
Dim cn As SqlClient.SqlConnection = New SqlClient.SqlConnection(strConnection)
Dim ds As New DataSet
Dim strSelect As String
'strSelect As String
strSelect = "SELECT * FROM " & YourTable & " WHERE [Search Field] = '" & Me.txtName.Text & "'"
Dim dscmd As New SqlClient.SqlDataAdapter(strSelect, cn)
dscmd.Fill(ds, "your table")
Me.Datagrid1.DataSource = ds
Me.Datagrid1.DataMember = "your table"
Dim con As Integer
con = Me.BindingContext(ds, "your table").Count
If con = 0 Then
MessageBox.Show("Recourd could not be found")
End If
End Sub
-
Aug 19th, 2007, 07:16 AM
#4
Re: Search From The Database
 Originally Posted by met0555
. . . I'm trying to make a program that will identify any file extension but I'm blocked here, . . .
What does this statment mean??? 
Additionally, the code you posted is VB.Net not VB6.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 19th, 2007, 07:17 AM
#5
Frenzied Member
Re: Search From The Database
Oh. I m sorry , I dont know vb.net. but in vb6 you can use a ADO connection and recordset to get data. I ll put some code.
to make a connection
Code:
Public dbcon As adodb.Connection
Set dbcon = New adodb.Connection
dbcon.CursorLocation = adUseClient
dbcon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\ControlList.mdb;"
to retrive data from your table and show in a data grid,
Code:
Private Sub datagrid_load()
DataGrid1.Visible = True
Dim op_grid_rs As New adodb.Recordset
Dim strsql As String
op_grid_rs.CursorLocation = adUseClient
strsql = " SELECT Control_UserLevel.*, Controls.ContainerID " & _
" FROM Controls INNER JOIN Control_UserLevel ON Controls.ControlName = Control_UserLevel.ControlName " & _
" ORDER BY Controls.ContainerID"
op_grid_rs.Open strsql, dbcon, adOpenStatic, adLockOptimistic
op_grid_rs.Sort = "UserLevel"
Set DataGrid1.DataSource = op_grid_rs
End Sub
Hope this helps.
-
Aug 19th, 2007, 07:18 AM
#6
Re: Search From The Database
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 20th, 2007, 02:19 AM
#7
Thread Starter
Frenzied Member
Re: Search From The Database
Hi, i've tried your code like this , but when i'm searching for a record that exist the form just freez and the button disable but it don't show the record.??
vb Code:
Option Explicit
Private strDataBaseName As String
Private strDBCursorType As String
Private strDBLockType As String
Private strDBOptions As String
Private rs As ADODB.Recordset
Private cn As ADODB.Connection
Private strSQL As String
Private Sub Command1_Click()
Dim b As Long
On Error GoTo Command1_Click_Error
Me.Command1.Enabled = False
strDBCursorType = adOpenDynamic 'CursorType
strDBLockType = adLockOptimistic 'LockType
strDBOptions = adCmdText 'Options
Set cn = New ADODB.Connection
Me.MousePointer = 11
cn.Open ConnectString()
With cn
.CommandTimeout = 0
.CursorLocation = adUseClient
End With
Set rs = New ADODB.Recordset 'Creates record set
strSQL = "SELECT * "
strSQL = strSQL & "FROM filei "
strSQL = strSQL & "WHERE [File Extension] ='" & Me.Text1.Text & "' "
strSQL = strSQL & "ORDER BY [File Extension];"
rs.Open strSQL, cn, strDBCursorType, strDBLockType, strDBOptions
If Not rs.EOF Then
For b = 1 To rs.RecordCount
'<=== Do whatever you need to do with the recordset here
rs.MoveNext
Next b
Else
MsgBox "The recordset contained no Records"
End If
Beep
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
On Error GoTo 0
Exit Sub
Command1_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Command1_Click of Form " & Me.Name
End Sub
Private Function ConnectString()
ConnectString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Fido-Dido\Desktop\File_Identifier.mdb;"
End Function
-
Aug 20th, 2007, 05:49 AM
#8
Re: Search From The Database
Could you print a sample of the data contained in the "filei" Table? Additionally, how many records are contained in that table?
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 20th, 2007, 05:55 AM
#9
Thread Starter
Frenzied Member
Re: Search From The Database
there are file extensions there are about 2000 records
-
Aug 20th, 2007, 06:29 AM
#10
Re: Search From The Database
Have you tried stepping through the code to see where it hangs up?
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 20th, 2007, 06:56 AM
#11
Thread Starter
Frenzied Member
Re: Search From The Database
I've tried with break points but i wasn't able to see where is the problem on the form i've only putted a button and a textbox does it need something else?
thanks
-
Aug 20th, 2007, 07:01 AM
#12
Re: Search From The Database
 Originally Posted by met0555
I've tried with break points but i wasn't able to see where is the problem on the form i've only putted a button and a textbox does it need something else?
thanks
So you were able to step through the code and it didn't hang up?
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 20th, 2007, 07:03 AM
#13
Re: Search From The Database
This is part of Mark's initial example
Code:
If Not rs.EOF Then
For b = 1 To rs.RecordCount
'<=== Do whatever you need to do with the recordset here
rs.MoveNext
Next b
Else
MsgBox "The recordset contained no Records"
End If
What did you replace
Code:
"'<=== Do whatever you need to do with the recordset here"
with?
-
Aug 20th, 2007, 08:13 AM
#14
Thread Starter
Frenzied Member
Re: Search From The Database
it's because i didn't change it with the right code, but anyway i used another code but i still get an error, i will post on a new post.
thanks
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
|