Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-11-26 : 08:34:20
|
| baskar writes "i have a problem.i developed a project in vb with ms access as database.Now i'm plannning to move to sql server...But i have problem.How to i write a sql query in sql server.. select * from Emp where empname=?the above query working well in access...but its not working in sql server...please help me soon..thanks and regards,Baskar" |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2002-11-26 : 08:47:14
|
quote: baskar writes "i have a problem.i developed a project in vb with ms access as database.Now i'm plannning to move to sql server...But i have problem.How to i write a sql query in sql server.. select * from Emp where empname=?the above query working well in access...but its not working in sql server...please help me soon..thanks and regards,Baskar"
You would need to use a variable which you could pass to the SQL. Perhaps the best solution would be a stored procedure..CREATE Procedure GetEmployeeDetails @empname varchar(50) asselect * from Emp where empname= @empnameYou then call the procedure with GetEmployeeDetails 'john smith'for employee John Smith. You can probably find out how to pass parameters to procedures in VB from lots of places more knowlegable about it than me.-------Moo. |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2002-11-26 : 09:15:18
|
| You'll need to use ADO and Command objects to call your sp's.Here is a small example of an call to an sp.Dim objConn As ADODB.ConnectionDim objComm As ADODB.CommandDim objRs As ADODB.RecordsetDim strConnectString As StringSet objConn = New ADODB.Connection Set objComm = New ADODB.CommandSet objRs = New ADODB.RecordsetstrConnectString = "Your connect string goes here"objConn.Open strConnectStringobjComm.CommandType = adCmdStoredProcobjComm.ActiveConnection = objConnobjComm.CommandText = "GetEmployeeDetails" objCommand.Parameters.Append objCommand.CreateParameter ("@empname",adWChar,adParamInput,50,"john smith")objRs.Open objComm, , adOpenStatic, adLockOptimistic'Process your recordset hereobjConn.CloseSet objRs = NothingSet objComm = NothingSet objConn = Nothing |
 |
|
|
|
|
|