Converting call to a stored procedure from C# to VB.net - stored-procedures

Dim sql1 As String = ("EXEC [dbo].[usp_GetReportData_All] #ReportID=N'{0}', #StartDate=N'{1}' #EndDate=N'{2}', #StartDate2=N'{3}' #EndDate2=N'{4}'", repotid1, startdata1, EndDate1, StartDate3,Enddate3 ) (this is what I tried to do in VB.net)
Ok normally I have this line of code in C# saved into a string then from there I use that string to run the stored procedure into a datatable. Apparently vb.net doesn't seem to like that format so I'm just wondering if it is possible to save this line into a string or not in vb.net
Oops mistake, this is what I do in C#:
string srcSQL = string.Format(then the line in parans up there)

As you can see in this examples of Console.Writeline(http://msdn.microsoft.com/en-us/library/aa324760(v=vs.71).aspx), you can use it for example:
Console.WriteLine("Grand total:\t{0,8:c}", Total);
For Example
Dim total As String
Dim result As String
total = "1000"
result = String.Format("restulado {0}", total)
MsgBox(result)
The var Total is formatted as currency

use String.Format("YourSQLText", parameter0, parameter1)

Related

How to Remove a certain part of a string (if exists)?

I am trying to make the EA look for a certain value in a string and if that value exists in the string then remove it.
I tried doing it using the StringReplace() but i noticed it only returns the number of replacements and didnt actually returned the updated string:
string v5="- .82523";
string temp2 = v5;
temp2= StringReplace(temp2," ","");
Print(v5,temp2);
in the above code there is a white space between "-" and ".82523" and i am trying to remove that white space.
so the string is - .82523 and i am trying to get -.82523 , which function can be used for this ?
initially i thought i could do it by using the StringReplace() function , but seems like it only returns the Number of replacements that had happened and not the updated string.
Thanks in Advance
You are using the StringReplace() function incorrectly. Try the following code (from your example).
string v5="- .82523";
string temp2 = v5;
StringReplace(temp2," ","");
Print("<",v5,"> <",temp2,">");

How can I get a count of files in a directory with scripting on Wonderware Archestra IDE

Two files "test.txt" and "test2.txt" were created in C:\tmp_dir. I want to know how many files in "C:\tmp_dir".
My code:
dim s as string;
s = System.IO.Directory.GetFiles("C:\tmp_dir");
LogMessage(s.Length);
But it's obviously wrong. It's returns 40(amount of symbols in path and both files) instead of 2. How can I do this properly?
From https://stackoverflow.com/a/15867350/804773 :
dim s as Integer;
s = System.IO.Directory.GetFiles("C:\tmp_dir").Count();
LogMessage(Text(s,"#"));
Tanks a lot! As you mentioned "s" must be Integer not string. And with "length" instead of "count" works fine.
dim s as integer;
s = System.IO.Directory.GetFiles("C:\tmp_dir").length;
LogMessage(s);

How to use date that is returned from a database in an MVC application

So i have written some code that executes an oracle database procedure or function
However, when I run a function I return a varray now i wonder what the mvc application gets from the database (I assume an array because I am using an OParray to execute the function); And how for example i would put these results in a viewbag list
the code that i use to execute the function is as folows
OracleParameter[] OPArray1 = new OracleParameter[] { new OracleParameter(null,OracleDbType.Varchar2, 10000, "9a15493038a7365e9ae4c0cfba1136cf", System.Data.ParameterDirection.Input) };
OracleCommand ODCommand1 = DBCon.StoredProcedureOrFunction("getpresentusers", OPArray1);
You need just convert to DateTimetype (C#)
Try this:
DateTime dateTime = DateTime.ParseExact(ds.Tables[0].Rows[0][0].ToString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

Calling Oracle 11g Stored Procedure Using VB6

I have a simple Oracle procedure as below. I am trying to call the procedure using VB6 and extract the output from the procedure.
CREATE OR REPLACE PROCEDURE EXTRACTTXN (reportdate IN DATE, p_recordset OUT SYS_REFCURSOR) AS
BEGIN
OPEN p_recordset FOR
SELECT
TXN_ID,
TXN_ACTION,
TXN_STATUS,
TXN_DATE,
TXN_AMOUNT
FROM TRANSACTIONS
WHERE
TRUNC(TXN_DATE) = TRUNC(reportdate)
END EXTRACTTXN;
The VB Code goes like this;
Sub FetchTransactions(ByVal ReportDate As Date, cnnMine as ADODB.Connection)
On Error GoTo TrapErr
Dim cmdMine As ADODB.Command, rsMine As ADODB.Recordset
cmdMine.ActiveConnection = cnnMine
cmdMine.CommandTimeout = 300
cmdMine.CommandType = adCmdStoredProc
cmdMine.CommandText = "EXTRACTTXN"
cmdMine.Parameters.Append cmdMine.CreateParameter("reportdate", adDate, adParamInput, , Format(ReportDate, "DD-MMM-YYYY"))
cmdMine.Parameters.Append cmdMine.CreateParameter("p_recordset", adVariant, adParamOutput)
Set rsMine = cmdMine.Execute
Do While rsMine.EOF
Debug.Print rsMine!TXN_ID, rsMine!TXN_ACTION, rsMine!TXN_STATUS, rsMine!TXN_DATE, rsMine!TXN_AMOUNT
rsMine.MoveNext
Loop
rsMine.Close
Exit Sub
TrapErr:
MsgBox Err.Number & " - " & Err.Description, vbExclamation, App.ProductName
End Sub
While running the code, I get the following Error:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'EXTRACTTXN'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Anything wrong in my code? Appreciate help.
Niz
The problem is that the types of your arguments as specified in your VB code don't match the types of the arguments as specified in your PL/SQL code. The most likely reason for your problem is that the Format function in VB6 returns a Variant type, not a Date type, and that Variant type is set to be a String type. See this for more information on the Format function.
In case you don't know, the way that Variant variables are set up is that they reserve 8 bytes to tell the world what the actual variable type is. So, if you pass your ReportDate in after applying the Format function to it, it will be a Variant that's telling the world it's a string. It's possible that the ADO Parameter object is happy with that (SQL Server is happy to parse properly-formatted strings into Date fields, after all) and Oracle isn't. In my limited experience with Oracle, I've found that it's fussier about that sort of thing than SQL Server.
Try losing the Format function and see if you at least get a different error.
I have managed to get this sorted. It's mainly due to me being new to Oracle and its complexity.
Here are the changes I made;
Stored Procedure Changes. Note that I have changed TRUNC(reportdate, 'DD') on the Where clause.
CREATE OR REPLACE PROCEDURE EXTRACTTXN (reportdate IN DATE, p_recordset OUT SYS_REFCURSOR) AS
BEGIN
OPEN p_recordset FOR
SELECT
TXN_ID,
TXN_ACTION,
TXN_STATUS,
TXN_DATE,
TXN_AMOUNT
FROM TRANSACTIONS
WHERE
TRUNC(TXN_DATE) = TRUNC(reportdate, 'DD')
END EXTRACTTXN;
VB Code Changes (Note that I have change the CommandText within parenthesis with a Call, removed the parameter name, changed the date format to DD/MMM/YYYY and removed the output parameter)
Sub FetchTransactions(ByVal ReportDate As Date, cnnMine as ADODB.Connection)
On Error GoTo TrapErr
Dim cmdMine As ADODB.Command, rsMine As ADODB.Recordset
cmdMine.ActiveConnection = cnnMine
cmdMine.CommandTimeout = 300
cmdMine.CommandType = adCmdStoredProc
cmdMine.CommandText = "{ call EXTRACTTXN}"
cmdMine.Parameters.Append cmdMine.CreateParameter(, adDate, adParamInput, , Format(ReportDate, "DD/MMM/YYYY"))
Set rsMine = cmdMine.Execute
Do While rsMine.EOF
Debug.Print rsMine!TXN_ID, rsMine!TXN_ACTION, rsMine!TXN_STATUS, rsMine!TXN_DATE, rsMine!TXN_AMOUNT
rsMine.MoveNext
Loop
rsMine.Close
Exit Sub
TrapErr:
MsgBox Err.Number & " - " & Err.Description, vbExclamation, App.ProductName
End Sub
The above worked perfectly.
Regards, Niz

How can I convert a C# multidimensional List to VB.Net

I'll start off by saying that everything I know about C# I've learned in the last few days researching how to convert a C# module to VB.Net 4.0.
The code below is a few select lines from the C# module that I'm converting to VB.Net. For the most part, it has been relatively simple and what I haven't been able to figure out, I've Googled and found an answer for. After about 10 hours of attempting to search for the answer(s) to the lines below, I finally came here looking for help.
As far as I can tell, the C# code creates a List of Integer, where the Integer is an array. The lines that I've included below that access that arrayed list.
My question is this: How can I convert this to VB.Net 4.0? or Can someone provide me with the working converted code?
Thanks in advance!
C# Code:
// mColumnPoint, mStartPoint, mEndPoint are all Integers
// Note that there is a mColumnPoint(int) and mColumnPoints(list) plural
private List<int[]> mColumnPoints;
mColumnPoints = new List<int[]>();
mColumnPoints.Add(new int[] { mStartPoint, mEndPoint });
for (int i = (int)mColumnPoints[mColumnPoint].GetValue(0);
i < (int)mColumnPoints[mColumnPoint].GetValue(1); i++)
{
// Stuff in for loop here
}
Well, It's an easy task:
Dim list As List(Of Integer()) = New List(Of Integer())()
list.Add(New Integer()() = { Class1.mStartPoint, Class1.mEndPoint })
For i As Integer = CInt(list(Class1.mColumnPoint).GetValue(0))To CInt(list(Class1.mColumnPoint).GetValue(1)) - 1
Next
I've used a great tool called "ILSpy",
http://sourceforge.net/projects/sharpdevelop/files/ILSpy/2.0/ILSpy_Master_2.1.0.1603_RTW_Binaries.zip/download
Simply build what you want using C# or vb.net then open that tool and browse for your *.exe or *.dll to see it in vb.net or c#, have fun :)
Module Module1
Structure segment
Dim startingPoint As Integer
Dim endingPoint As Integer
End Structure
Sub Main()
Dim mStartPoint, mEndPoint, mColumnPoint As Integer
Dim mColumnPoints As New ArrayList
Dim nextSegment As segment
mStartPoint = 1
mEndPoint = 42
mColumnPoint = 0 ' The first element in the array
nextSegment.startingPoint = mStartPoint
nextSegment.endingPoint = mEndPoint
mColumnPoints.Add(nextSegment)
Dim startValue As Integer = mColumnPoints(mColumnPoint).startingPoint
Dim limit As Integer = mColumnPoints(mColumnPoint).endingPoint
Dim i As Integer
For i = startValue To limit
' do something
Console.WriteLine("Cycle # " & i.ToString)
Next
Console.WriteLine("Done " & i.ToString)
End Sub
End Module

Resources