|
sorry, nothing seems to come out of the program when i press "search" after i have put in bob in txtSearch
that is why i was wandering if there was anyway of highlighting the database record that MAY have been found. Or finding out if the program has actually searched?
Dan
|
|
|
|
|
First, are you selecting data from a table or from a grid? Try to run your query from SQL Management Studio, or run it without the filter to see if it returns anything at all.
You should indeed use the ADODB.Command (with parameters!) to return a ADODB.RecordSet. More information can be obtained here[^]
I are Troll
|
|
|
|
|
Thanks for the help, umm this seems a little to complicated.
All i originally wanted was a search box with a button saying search, when the user types someting in the textbox and hits search i wanted the database to display that record.
The database all works fine it just the search box that i need help with
I found this website however i am new to vb6 so sorry if the link you showed me is a lot easier to use than the current way.
http://www.bigresource.com/Tracker/Track-vb-wINQIg4YXj/[^]
many people have been saying that this is the best way
"SELECT * From DataGrid1 WHERE [First_Name] = " & "'" & First_Name & "'" & "" however i cant't seem to get this to work as the code doesn't react. I just click the button and nothing happens.
If you can help me that would be very helpful.
|
|
|
|
|
I seem to have got a little bit further
DataGrid1.RecordSelectors = "SELECT * From Adodc1 WHERE [First_Name] = '" & txtSearch.Text & "'"
this seems to do more than the old code, however brings up an error saying type
run time error 13
type mismatch
I think i am nearly there (probably not but hey)
If anybody can help that would be great!!
Dan
|
|
|
|
|
At first I would like to suggest...Stop writing code in vb6..Start with VB/C#.Net. If you are bounded to write code on vb6
it will be better to read vb6 book first...
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Usually I'd agree with getting a book first, but VB6 is a piece of antique. You fix it and get the Hell out or there
Let's try and divide it into two separate problems; first you'd need to get an argument from a textbox. The second task is to use this argument in the SQL statement. So, the code would be changed to something like this;
Dim Arg$
Arg$ = txtSearch.Text
Dim Statement$
Statement$ = "SELECT * FROM [tablename] WHERE [First_Name] = '" & Statement$ & "'"
DataGrid1.RecordSelectors = Statement$ This is not the "ideal" construct, as it leaves you vulnerable to hackers. That's something that you can worry about when the code works though. Put a breakpoint on the last line by clicking in the gutter, run your code and press Ctrl-G when you reach the breakpoint. That will cause the "immediate"-window to pop up.
Type "? Statement$" and press enter in that Window. VB6 should react by showing you the contents of the Statement$ variable. You can copy/paste this SQL-statement here, if you want to have it verified.
I are Troll
|
|
|
|
|
Thank you ever so much for your help, unfortunately i am still receiving a few errors.
I ma probably doing something wrong but just want to clarify. Table name is the access file? or is it the table you have but in vb6?
And the First_Name is the column you want to search?
I have tried the code but am still receiving an error message. run time error 13
type mismatch
I think i'll glad to get this done and move onto a more up to date language!!!
Thanks again
Dan
|
|
|
|
|
offroaderdan wrote: I ma probably doing something wrong but just want to clarify. Table name is the access file? or is it the table you have but in vb6?
It's the name of the table, as it appears in the Access-file. Click on the Access-file one, hold down shirt, and double-click. That should open the database. The should be a list of tables. You can test your SELECT statement directly in Access, by creating a new Query.
offroaderdan wrote: And the First_Name is the column you want to search?
Yup
I'd go for something like this;
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As ADODB.Recordset
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Northwind.mdb;User Id=admin;Password=;"
con.Open
cmd.CommandText = "SELECT * FROM [Employees]"
cmd.CommandType = adCmdText
cmd.ActiveConnection = con.ConnectionString
Set rst = cmd.Execute
rst.Close
con.Close
Set rst = Nothing
Set cmd = Nothing
Set con = Nothing
I are Troll
|
|
|
|
|
Thanks for the reply
I am currently getting an error saying unrecognized database format in vb6?
Umm the database file is all fine? I don't know why this has happened.
I have tried to code a different way as today one of my mates let me borrow a book in vb6 and i found a db way (so thought i'd try it)
has anyone ever come across this error and if so how do you get rid of it??
Many thanks
Dan
|
|
|
|
|
|
|
hi all,
i want to write the content of a text file to another txt file exactly like what i have in original file.
i used write,writeline and put functions. but to my surprise, i found the text file is benig written without the new line character.
for example:
original file content:
aefaiojefioae
fafajfpfjafaffjaeiofjafjfjfi
faijfoijf
faioj
Para 2:
fafaopfopfkaokfopfaopkfopkopafopkfpoaf. fijaoijij
fafijoifjfiajparwto
MY COPIED FILE content:
aefaiojefioae fafajfpfjafaffjaeiofjafjfjfi faijfoij ffaioj Para 2: afaopfopfkaokfopfaopkfopkopafopkfpoaf. ijaoijij fafijoifjfiajparwto
Can anyone help me on how to write the content of the file exactly as what i have in original?
Thanks,
mahi.
|
|
|
|
|
Why not just use system.io.file.copy?
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
File.Copy is the simple way. Copying bytes, not characters (hence using a byte array), is the alternative.
|
|
|
|
|
Is the text in memory, or is it still in the original file?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
text is not in memory ..its in original text file only.
|
|
|
|
|
Then do what everyone else said, and just use File.Copy
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I agree. I think File.Copy would be your best solutions if you want your text file to be exactly the same as the original.
modified on Wednesday, January 27, 2010 10:02 AM
|
|
|
|
|
i have 2 following solution
the first
sqlcommand1.commandText = "insert into customers values('firstName','lastName','phone')
SqlCommand1.ExecuteNonQuery()
the second
'fill into datagridview
SqlCommand1.CommandText = "select * from customers "
SqlDataAdapter1.SelectCommand = SqlCommand1
SqlDataAdapter1.Fill(DataSet1, "customers")
DataGridView1.DataSource = DataSet1
DataGridView1.DataMember = "customers"
'add new row into datatable
row = DataSet1.Tables("customers").NewRow()
row.Item(0) = "firstName"
row.Item(1) = "lastName"
row.Item(2) = "phone"
DataSet1.Tables("customers").Rows.Add(row)
'update data
SqlCommandBuilder1 = New SqlCommandBuilder(SqlDataAdapter1)
SqlCommand1.CommandText = "select * from customers "
SqlDataAdapter1.InsertCommand = SqlCommandBuilder1.GetInsertCommand
SqlDataAdapter1.Update(DataSet1, "customers")
Can you tell me what 's difference between those ?
And which is solution with higher performance
Thank you very much!!
|
|
|
|
|
These two are doing different things, You cant Compare them. I suggest you buy a Book
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I see a lot of this.
Clearly the first is better etc. Why bother filling a dataset in order to perform an insert? The second option will produce the same SQL at the end of the day, but at high cost in processing to generating something you can type yourself in seconds.
|
|
|
|
|
The first one is a little better than the second b/c your using a bit more processing power on your app server to create the dataset you have on the second. In the first, most of the processing will be performed on the database server which is optimized for doing such computations.
modified on Wednesday, January 27, 2010 10:01 AM
|
|
|
|
|
Dear All,
Could any body give me the line code for the given query.
1. If I am clicking mouse button on Row 1 column 3
then it will show in Msgbox "selected Column 3"
2. If I am clicking mouse button on Row 1 column 4
then it will show in Msgbox "selected Column 4"
.........so on.
Thanks
Ashish
|
|
|
|
|
Private Sub MSFlexGrid1_Click()
MsgBox CStr(MSFlexGrid1.Colsel)
End Sub
I are Troll
|
|
|
|
|
Hi,
The below code return 0 ,Even I click on 1,2.3 ...soon column
Private Sub MSFlexGrid1_Click()
MsgBox CStr(MSFlexGrid1.Colsel)
End Sub
Thanks
Ashish
|
|
|
|