passing parameter to Dataenvironment visual basic - vb6

HI,
I am working on Visual Basic DataEnvironment I have written SQL command but i need to pass some parameter from one of my form object.
I have tried this
SELECT * from user WHERE userid= form1.textbox1.text
but it doesn't seems to be work. Any Idea how to pass parameter.

I would suggest performing a filter on the recordset inside your DataEnviroment instead placing the WHERE clause where your SQL statement is defined.
With DataEnvironment1.rsDataTable
.Filter = "UserID = " & textbox1.text
End With
Please check out the following links. I hope this helps.
http://msdn.microsoft.com/en-us/library/aa231245(v=vs.60).aspx
http://pages.cpsc.ucalgary.ca/~saul/vb_examples/tutorial4/index.html
Also, if possible I would recommend using ADO instead of the DataEnvironment.

Related

QTP recognising a JavaEdit object but not able to set a value when running the script

I have written a simple script to log into a Java app where it fills in username and password, and then clicks on the "Connect" button".
Set UVC = JavaDialog("UVC")
wait(20)
If UVC.Exist Then
UVC.JavaEdit("JTextField").Set "admin"
wait(2)
UVC.JavaEdit("PSW").SetSecure "5256833195fsdqsdsqd447e4beefsdsdqd"
wait(5)
UVC.JavaButton("Connect").Click
Else
print "Console is not present"
End If
It's strange as QTP is identifying my password field properly. When running the following code I get a value back as expected:
MsgBox Main.JavaEdit("password").GetROProperty("attached_text")
I have also tried to set the password without encrypting it but it's also not working.
PS: the same script was working before and has since stopped working for an unknown reason!!!
Thanks in advance.
Replace
UVC.JavaEdit("PSW").SetSecure "5256833195fsdqsdsqd447e4beefsdsdqd"
with
UVC.JavaEdit("PSW").Click 1,1
UVC.JavaEdit("PSW").SetSecure "5256833195fsdqsdsqd447e4beefsdsdqd"
and it will work even with replay mode = "event". If you want to beautify this, you can use a click in the middle of the field, like in:
With UVC.JavaEdit("PSW")
.Click .GetROProperty ("width")\2, .GetROProperty ("height")\2
.SetSecure "5256833195fsdqsdsqd447e4beefsdsdqd"
End With
It seems that most Java password fields must first be focussed to be SetSecure-able.
Just to be sure.. check whether the field is enabled by testing .getroproperty("editable").
Use any of these methods to set text in Java Edit field.
You could use JavaEdit("PSW").Object.Settext method - this uses the JTextField in JavaSwing object properties
You could use setfocus method before entering the string in the field
Get the position of the test field
x = JavaEdit("PSW").Getroproperty("abs_x")
y = JavaEdit("PSW").Getroproperty("abs_y")
Set DRP = CreateObject("Mercury.DeviceReplay")
DRP.MouseClick x,y,"0"
DRP.SendString "the string"
You could also use JavaEdit's type object
Any of these methods should work for you. If not tough luck.. :)
Thanks for your answers but none of your suggestions worked, I have ended up using a basic turnaround :
UVC.JavaEdit("JTextField").Set"admin"
UVC.JavaEdit("PSW").Click 1,1
UVC.JavaEdit("PSW").SetSecure"52581237d889935df36ae78587773a641f40"
UVC.JavaButton("Connect").Click
wait (5)
While JavaDialog("Login Error").Exist
JavaDialog("Login Error").JavaButton("Ok").click
UVC.JavaEdit("PSW").RefreshObject
UVC.JavaEdit("PSW").SetSecure"52581237d889935df36ae78587773a641f40"
UVC.JavaButton("Connect").Click
Wend
I really don't get it how could the same function work sometimes and sometimes not!!

mvc3 dapper parameter issue

I have dapper working correctly, but it is unsecure as in I haven't been using parameters, how can I best turn my dapper variables into parameters for instance this is the unparameterized code that I had that worked..
var getinfo = sqlConnection.Query<test>("Select name,location from tests where location="+ myplace).FirstOrDefault();
myplace is a textbox that users put information on, now when I tried to parameterized that code like
var getinfo = sqlConnection.Query<test>("Select name,location from tests where location='#location'", new {location = myplace}).FirstOrDefault();
I get absolutely no returns back, yet no error messages. What can I be missing here or whats the best way to parameterized variables.
You do not need to place the single quotes around the parameter. Hope this helps.
var getinfo = sqlConnection.Query<test>("Select name,location from tests where location=#location", new {location = myplace}).FirstOrDefault();

DbLimitExpression requires a collection argument

Does anyone have the faintest idea what this error means please and how to resolve it? All my research is drawing a blank, I can see how to set it on MSDN but it doesn't explain it in a way that explains to me what the issue is. If I remove some of my LINQ queries to set viewbag items then it seems to resolve it but the moment I set new ones and pass them into my view to generate a mail for MVCMailer it comes back. Not sure if its a viewbag issue or simply that I am calling too many linq queries to generate them to pass to the view.
I am very stuck (again)..........
Cheers,
Steve.
DbLimitExpression requires a collection argument.
Parameter name: argument
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: DbLimitExpression requires a collection argument.
Parameter name: argument
An example of the code is:
var VBSalutation = from A in context.Salutations
where A.SalutationId == policytransaction.SalutationId
select A.SalutationName;
ViewBag.Salutation = VBSalutation.FirstOrDefault();
This is repeated for various parameters and then passed to the view.
Well, I faced a similar problem and solved it. Problem was in WHERE clause: data type of left side equal operator (=) sign was not matching with data type of right side. So in your scenario:
where A.SalutationId == policytransaction.SalutationId
SalutationID of A might be an INT and SalutationId of policytransaction might be a string (This is how it was in my case).
I solved it by assigning policytransaction.SalutationId to an Int variable and using it:
int myIntVariable = Convert.ToInt16(policytransaction.SalutationId);
...//some code here
where A.SalutationId == myIntVariable;
Please also note that you cannot directly cast your variables directly in Linq else you'll get an error "LINQ to Entities does not recognize the method". You'll have to use a temp variable and then apply the where clause.
Try ViewBag.Salutation = VBSalutation.SingleOrDefault();

Add item to Error List in Macro

I want to notify the user of the macro if something went wrong during the execution of the macro. I was wondering if it would be possible to add an item to the Visual Studio error list?
It is possible to do so from within an AddIn (like here), but I would like to do the same thing from a macro.
Edit
To further clarify what i want to achive, here is the sample from the Samples macro library (Alt+F8 -> Samples -> Utilities -> SaveView())
Sub SaveView()
Dim name As String
name = InputBox("Enter the name you want to save as:", "Save window layout")
If (name = "") Then
MsgBox("Empty string, enter a valid name.")
Else
DTE.WindowConfigurations.Add(name)
End If
End Sub
Instead of the MsgBox("...") alert I want to put the error into the VS error list.
You can add an item in the Task List easily from your macro. Just use the AddTaskToList method from that article and change m_objDTE to DTE. I've tried it and it worked.
However, adding the item in Error List, is probably impossible. You need to call VS services, see how adding an error is done in an add-in. I created a macro from this code and it didn't work. In general, VS services don't work in macros. I was able to create ErrorListProvider successfully. I could access it's methods and properties. But calling ErrorListProvider.Task.Add caused COM exception. If you want to play with it, several notes:
As described in the article, you need to get 4 assemblies out of the GAC e.g. to c:\dlls\ directory. Since Macros IDE doesn't allow you to browse when you Add Reference, you need to copy these dlls into ...\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies directory (change the 10.0 to your VS version). Then, when you Add Reference in Macros IDE, you should see the assemblies.
The GetService function always returned Nothing. Add the following field to the class:
Private serviceProvider As IServiceProvider = New Microsoft.VisualStudio.Shell.ServiceProvider(CType(DTE, Microsoft.VisualStudio.OLE.Interop.IServiceProvider))
and in GetService function change line:
objService = Microsoft.VisualStudio.Shell.Package.GetGlobalService(serviceType)
to
objService = serviceProvider.GetService(serviceType)
As I wrote, everything seems OK then but ErrorListProvider.Task.Add fails.
I think that for your situation outputting something to your own output pane would be more suitable. The error list is generally used for errors within the project the user is working on, not for errors caused by running macros. Especially when someone says it can't be done. :)
Outputting to your own output pane is pretty easy:
DTE.Windows.Item(Constants.vsWindowKindOutput).Activate()
Dim panes As OutputWindowPanes = window.OutputWindowPanes
Dim my_pane As OutputWindowPane
Try
my_pane = panes.Item("SaveView")
Catch exception As System.ArgumentException
my_pane = panes.Add("SaveView")
End Try
my_pane.Activate()
my_pane.OutputString("Empty string, enter a valid name." + vbCrLf)
Hope this helps.
Cheers,
Sebastiaan
Is this not what you want?
HOWTO: Add an error with navigation to the Error List from a Visual Studio add-in
http://www.mztools.com/articles/2008/MZ2008022.aspx

ADODB Recordset.Recordcount corruption with oracle (ASP)

For some unknown reason, when I try to read the RecordCount property from an ADODB.Recordset object in ASP it causes strange data corruption that doesn't appear to follow any particular pattern that I can find. I'm using ASP to connect to an Oracle 10g database. The following is the code I am using.
c_objRS.Open strSql, objPage.objCn, adOpenStatic, adLockReadOnly, adCmdText
DB_ReadListCount = c_objRS.RecordCount
For some reason, some CLOB objects that are read from this recordset return the value null ONLY if I call c_objRS.RecordCount. If I do not call it, or if I call c_objRS.Close then c_objRS.Open, then it works just fine. Also c_objRS.Requery appears to fix the issue.
I don't really want to use these methods at the moment because I fear some level of data corruption via opening and closing the result set and I do not want to re-run another query since the table in question can eventually become quite huge.
I'm currently using ODAC 11.1.0.6.21
Any help would be much appreciated!
Try MoveNext or MoveLast then use MoveFirst. This might help.
Try this:
If Not c_objRS.EOF Then
c_objRS.MoveNext
DB_ReadListCount = objRS.RecordCount
Else
DB_ReadListCount = 0
End If

Resources