Visual Basic/VB problems

Advertisement


Question

screen shot
I want to check a text box value with sql2000 server db using sql query and show the new form. Where as I can’t compare the value
Please see the coding and attachment and help me where I have done the mistake & tell me how to compare the database value in if statement using sql query, what I am doing is
Private Sub Print_Cmd_Click()
Databse connection has been already opened using connection string even though i opening again
Dim Connection As New ADODB.Connection
Dim Command As New ADODB.Command
Dim eid As String
Dim strsql As String
Set Connection = New ADODB.Connection
Connection.ConnectionString = "driver={SQL Server};server=SRV-FTZ-SQL;uid=sa;pwd=;database=exactpayroll"
Connection.Open
Command.ActiveConnection = Connection
eid = Empid_txt.Text
strsql = " SELECT  empid FROM EmployeeMaster where empid= & eid "
If strsql = eid Then
Prt_Msg.Show
Else
MsgBox (" Please enter a valid Employee id")
End If
End Sub
Can you please help
Now you can see the data grid has the database value I am giving a Id which is present in the data base , but it executes the else statement


Answer
strsql is just a string and not the recordset's field value
you need to open it as
dim rec as adodb.recordset
'set rec=new adodb.recordset
rec.Open (esql), conn, adOpenStatic, adLockReadOnly

if rec.fields(fieldname/number)=eid ( you need to convert to Val(empid_txt.txt))
then
...


rec.close

Ravindra

Expertise

visual basic application programming from design to access information, sql, engineering and commercial applications. access databases, excel.(VB6) basic questions in vb 2008. Optional: 1)a large number of people want me to do work which takes some time and effort. can do projects in vb 2008. Pl.note that i would like to be paid for such work. 2) if you want me to spend quality time and do special work, i expect to be paid a reasonable price for my time. 3) if you are pleased with my reply you could consider a good amount. 4) you can visit my website http://ravindra.coolpage.biz

Experience

programming since the past 15 years. have completed a large number of projects in Industrial applications, finance,accounts, correspondence. excel macros etc

Education/Credentials
engineering, management degrees.

Past/Present Clients
project work for a Norway company,USA company and a Canadian company completed. Freelance Project work and Teaching. helping programmers with their work
teaching vb

©2012 About.com, a part of The New York Times Company. All rights reserved.