Getting Error at insert on Visual Basic .Net - vb.net

im trying to make an insert to my Database and im receiving an error, is my first time with VB.Net so any help would be greatly appreciated.
Here is the code:
Sub InsertGestion(ByVal s As Object, ByVal e As EventArgs)
Dim Records() As String
Records = Split(TBComment.Text, vbCrLf)
Dim record As Integer
For record = 0 To UBound(Records)
oracleCommand = New OracleCommand("INSERT INTO ACTFIL (ACACCTG,ACACCT,ACACTDTE,ACSEQNUM,ACACCODE,ACRCCODE,ACCIDNAM,ACCOMM) values ('1','" + TBNum.text + "','" + TBFecha.Text + "',"+ (record+1) +",'"+TBCodAc.text+"','"+TBCodRes.text+"','"+TBGestor.Text+"','"+record+"')", oracleConexion)
Try
oracleConexion.Open()
oracleCommand.ExecuteNonQuery()
Catch ex As Exception
status.Text = "ERROR al insertar la gestiĆ³n " + ex.Message + "'" '& ex.Message
Finally
oracleConexion.Close()
Response.Redirect("gestiones.aspx?credito=" + Request.QueryString("credito") + "")
End Try
Next
End Sub
And the Error:
FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +717374
Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +114
[InvalidCastException: Conversion from string "INSERT INTO ACTFIL (ACACCTG,ACAC" to type 'Double' is not valid.]
Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +717687
ASP.marcador_gestiones_aspx.InsertGestion(Object s, EventArgs e) in G:\vta-paqV2\marcador\gestiones.aspx:62
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
This was originally an update and it was working, i just modified the OracleCommand.
Btw, i notice this is not a secure way to execute the queries, if someone can point me on the right direction i'd really appreciate it.

Extract the oracle command from the query and run on Oracle client. That will let you know if there is anything wrong with your oracle command.
Secondly you can use string.format to form your query rather using + operator.
Secure approach to deal with query inputs is through input parameters. You can check below links.
http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracleparameter.aspx
http://blogs.msdn.com/b/alextch/archive/2007/08/21/using-data-parameters-with-oracle-data-provider-for-net.aspx
I hope this helps.
Thanks!
Dhananjay

Related

Conversion from string "F:\Steam\steamapps\common\FSX" to type 'Double' is not valid

I am making an installer for a flight sim thing but when I use them following code I get this message: Conversion from string "F:\Steam\steamapps\common\FSX" to type 'Double' is not valid
Here is the code:
Private Sub FsX1Button2_Click(sender As Object, e As EventArgs) Handles FsX1Button2.Click
Try
If TextBox1.Text = Not "" Then
My.Computer.FileSystem.DeleteFile(TextBox1.Text & "\SimObjects\Misc\ControlTower\texture\ControlTower_Instruments_lm.dds")
My.Computer.FileSystem.DeleteFile(TextBox1.Text & "\SimObjects\Misc\ControlTower\texture\ControlTower_Instruments.dds")
My.Computer.FileSystem.DeleteFile(TextBox1.Text & "\SimObjects\Misc\ControlTower\texture\ControlTower_Countertops2_lm.dds")
My.Computer.FileSystem.DeleteFile(TextBox1.Text & "\SimObjects\Misc\ControlTower\texture\ControlTower_Countertops2.dds")
Dim bravo() As Byte = My.Resources.ControlTower_Countertops2
System.IO.File.WriteAllBytes(TextBox1.Text & "\SimObjects\Misc\ControlTower\texture\ControlTower_Countertops2.dds", bravo)
Dim charlie() As Byte = My.Resources.ControlTower_Countertops_lm
System.IO.File.WriteAllBytes(TextBox1.Text & "\SimObjects\Misc\ControlTower\texture\ControlTower_Countertops2_lm.dds", charlie)
Dim delta() As Byte = My.Resources.ControlTower_Instruments
System.IO.File.WriteAllBytes(TextBox1.Text & "\SimObjects\Misc\ControlTower\texture\ControlTower_Instruments.dds", delta)
Dim foxtrot() As Byte = My.Resources.ControlTower_Instruments_lm
System.IO.File.WriteAllBytes(TextBox1.Text & "\SimObjects\Misc\ControlTower\texture\ControlTower_Instruments_lm.dds", foxtrot)
Me.Hide()
MsgBox("Installed successfully", MsgBoxStyle.Information, "")
End
Else
MsgBox("Select path", MsgBoxStyle.Exclamation, "")
End If
Catch ex As Exception
MsgBox("Error exporting the files (" + ex.Message + ")", MsgBoxStyle.Critical, "Error")
End Try
End Sub
Private Sub FsX1Button1_Click(sender As Object, e As EventArgs) Handles FsX1Button1.Click
FolderSelect.ShowDialog()
TextBox1.Text = FolderSelect.SelectedPath
End Sub
So you press the button and select the folder and it sets TextBox1 to the file path. Then it adds the files.
However, When i use the following code:
Try
My.Computer.FileSystem.CreateDirectory("C:\ProjectRazerFiles")
Dim b() As Byte = My.Resources.ControlTower_Countertops2
System.IO.File.WriteAllBytes("C:\ProjectRazerFiles\ControlTower_Countertops2.dds", b)
Dim c() As Byte = My.Resources.ControlTower_Countertops_lm
System.IO.File.WriteAllBytes("C:\ProjectRazerFiles\ControlTower_Countertops2_lm.dds", c)
Dim d() As Byte = My.Resources.ControlTower_Instruments
System.IO.File.WriteAllBytes("C:\ProjectRazerFiles\ControlTower_Instruments.dds", d)
Dim f() As Byte = My.Resources.ControlTower_Instruments_lm
System.IO.File.WriteAllBytes("C:\ProjectRazerFiles\ControlTower_Instruments_lm.dds", f)
MsgBox("Exported successfully", MsgBoxStyle.Information, "")
Catch ex As Exception
MsgBox("Error exporting the files (" + ex.Message + ")", MsgBoxStyle.Critical, "Error")
End Try
It works?
Can you help me with the top one please?
Any help would be gratefully appreciated
The issue is presumably here:
If TextBox1.Text = Not "" Then
That code doesn't make sense. It's trying to negate an empty String and compare the result to another String. If you're trying to test that the TextBox is not empty then that would be like this:
If TextBox1.Text <> "" Then
First, you obviously have option strict set to off, turn it on and fix all of the errors you get (including this one). If you have more than a few hundred, you should turn it on at the project level and off at the file level.
The Not "" is obviously turning the empty string into a double (using the equivalent of Val("")) and then performing a bitwise Not on it and then trying to compare the result to TextBox1.Text by converting it's value to a double, which it fails to do and thus your exception.
Option Strict Off allows these types of comparisions, and in some cases it even works out to roughly what you meant to happen. In other cases, as this example shows, it just causes a compile time error to become a runtime error. That is seldom an improvement.

Is this err caused by trying to process too many controls on the web form?

I get this err page:
Server Error in '/EMS/customerreportingnet' Application.
Operation is not valid due to the current state of the object.
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.InvalidOperationException: Operation is not valid due to the current state of the object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Operation is not valid due to the current state of the object.]
System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +4198079
System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +60
System.Web.HttpRequest.FillInFormCollection() +189
[HttpException (0x80004005): The URL-encoded form data is not valid.]
System.Web.HttpRequest.FillInFormCollection() +11196408
System.Web.HttpRequest.get_Form() +119
System.Web.TraceContext.InitRequest() +1188
System.Web.TraceContext.VerifyStart() +133 System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +11307449
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +452
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5491
...when I click the button which fires this code:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim upd8DML As String = "UPDATE CustomerCategoryLog SET Category = 'Exploding' WHERE Unit = #Unit And MemberNo = #MemberNo AND Custno = #CustNo"
Dim coName As String
Dim argVals(2) As String
Dim _Unit As String
Dim _MemberNo As String
Dim _CustNo As String
Dim curIndexVal As String
For Each cntrl As Control In Me.Controls
If TypeOf cntrl Is CheckBox Then
If DirectCast(cntrl, CheckBox).Checked = True Then
curIndexVal = DirectCast(cntrl, CheckBox).ID
coName = GetLabelTextForID(curIndexVal)
argVals = GetArgValsForCompanyName(coName)
_Unit = argVals(0)
_MemberNo = argVals(1)
_CustNo = argVals(2)
Using conn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")), _
cmd As New SqlCommand(upd8DML, conn)
cmd.Parameters.Add("#Unit", SqlDbType.VarChar, 50).Value = _Unit
cmd.Parameters.Add("#MemberNo", SqlDbType.VarChar, 50).Value = _MemberNo
cmd.Parameters.Add("#CustNo", SqlDbType.VarChar, 50).Value = _CustNo
conn.Open
cmd.ExecuteScalar()
End Using
End If
End If
Next
End Sub
My guess is that this is because the literally thousands of label/checkbox pairs of controls on the form are too much to handle (no pun intended). If this reckoning is right, what is the limit of controls that the page will host without whin[g]ing?
Is there a workaround where I can deal with thousands of label/checkbox pairs?
Or is it the number of update statements that are causing the problem?
The err msg seems to indicate too many controls to deal with...

Asp.net application suddenly stopped responding to requests

Good day, I am a newbie in .net programming and also IIS web deployment configuration.
Currently, I have an asp.net application that runs using Framework 4.5 on IIS. For the first month of having the application deployed on the server, it was running fine and smoothly. However, recently the application had issues whereby the login page would actually load but when the users key in their credentials, the page loading timer would show and it disappears, leaving the user stranded, unable to login.
In addition, the server had undergone security procedures as stated below:
Windows Hardening (Using Windows Server 2012)
SQL Server Hardening (SQL Server 2012) and port was changed to 8001
Also, the architecture of the application is that:
The Application is deployed in AMLWEB server
The SQL Server Database is in AMLDB server
So, the connection actually goes across server and the login authentication is actually authenticated against Active Directory.
The screenshot as attached:
Unhandled exception screenshot
When checked on the event viewer, the below warning was seen that may suggest to be contributing to the issue:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 1/18/2015 5:27:15 PM
Event time (UTC): 1/18/2015 9:27:15 AM
Event ID: 2ac169fff7284e86b7b0844e5d9ccab1
Event sequence: 4
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/1/ROOT/AML-1-130660468323976167
Trust level: Full
Application Virtual Path: /AML
Application Path: D:\AML\
Machine name: AMLWEB
Process information:
Process ID: 6756
Process name: w3wp.exe
Account name: IIS APPPOOL\.NET v4.5
Exception information:
Exception type: InvalidOperationException
Exception message: The ConnectionString property has not been initialized.
at System.Data.SqlClient.SqlConnection.PermissionDemand()
at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at DBManager.DBManager.OpenConnection(String DBStrConn, Int16 DBType) in C:\Users\TESS-HP003\Desktop\AML\ES_Library\DBManager\DBManager.vb:line 50
at DBManager.DBManager.ExecuteSQLQuery_ReturnDS(String& ReturnErrorMsg, String SqlString, String DBConnString, Int16 DBType) in C:\Users\TESS-HP003\Desktop\AML\ES_Library\DBManager\DBManager.vb:line 190
at SQLAdminQueryManager.AdminQueryManager.AdminQueryManager_Staff_Login.Staff_Login_Retreive(cor_staff AppEntity, String DbSQLConnString, String DbType, String& ReturnErrorMsg, Object& ReturnObjDataset, String AccessType) in C:\Users\TESS-HP003\Desktop\AML\ES_Library\SQLAdminQueryManager\AdminQueryManager.vb:line 65
at Login_page_LDAP_Code.LoginButton_Click(Object sender, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Request information:
Request URL: https://amlweb/AML/Login_page.aspx
Request path: /AML/Login_page.aspx
User host address: 10.1.67.61
User:
Is authenticated: False
Authentication Type:
Thread account name: IIS APPPOOL\.NET v4.5
Thread information:
Thread ID: 10
Thread account name: IIS APPPOOL\.NET v4.5
Is impersonating: False
Stack trace: at System.Data.SqlClient.SqlConnection.PermissionDemand()
at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at DBManager.DBManager.OpenConnection(String DBStrConn, Int16 DBType) in C:\Users\TESS-HP003\Desktop\AML\ES_Library\DBManager\DBManager.vb:line 50
at DBManager.DBManager.ExecuteSQLQuery_ReturnDS(String& ReturnErrorMsg, String SqlString, String DBConnString, Int16 DBType) in C:\Users\TESS-HP003\Desktop\AML\ES_Library\DBManager\DBManager.vb:line 190
at SQLAdminQueryManager.AdminQueryManager.AdminQueryManager_Staff_Login.Staff_Login_Retreive(cor_staff AppEntity, String DbSQLConnString, String DbType, String& ReturnErrorMsg, Object& ReturnObjDataset, String AccessType) in C:\Users\TESS-HP003\Desktop\AML\ES_Library\SQLAdminQueryManager\AdminQueryManager.vb:line 65
at Login_page_LDAP_Code.LoginButton_Click(Object sender, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Custom event details:
However, the connection string was indeed had been set up properly as below:
Web.config
<connectionStrings>
<add name="AMLDBConnectionString" connectionString="Data Source=AMLDB01, 8001;Initial Catalog=AML_DB;integrated security=true; uid=sa; pwd=p#ssw0rd"/>
</connectionStrings>
And it was set up as a global variable as so:
GlobalSQLConnString = ConfigurationManager.ConnectionStrings("AMLDBConnectionString").ToString
GlobalDBType As Int16 = 1
The line which actually executed to connect to the DB:
blnReturnValue = objSqlQuery.Staff_Login_Retreive(objBE, GlobalSQLConnString, GlobalDBType, strErrorMsgReturn, returnDS, "S")
The method invoked:
Public Function Staff_Login_Retreive(ByVal AppEntity As BusinessEntities.cor_staff, _
ByVal DbSQLConnString As String, ByVal DbType As String, _
ByRef ReturnErrorMsg As String, ByRef ReturnObjDataset As Object, _
Optional ByVal AccessType As String = "S") As Boolean
With AppEntity
SQlQuery = "SELECT * "
SQlQuery += " FROM cor_staff "
SQlQuery += " WHERE cor_staff.cor_userid =N'" & AppEntity.cor_userid & "'"
End With
'
If AccessType.ToUpper = "R" Then
ReturnObjDataset = ExecuteSQLQuery_ReturnIDR(ReturnErrorMsg, SQlQuery, DbSQLConnString, DbType)
Else
ReturnObjDataset = ExecuteSQLQuery_ReturnDS(ReturnErrorMsg, SQlQuery, DbSQLConnString, DbType)
End If
'
If ReturnErrorMsg.Trim.Length = 0 Then
Return True
Else
Return False
End If
'
End Function
Edited
Since the above code would actually run through and would actually be invoked on this line:
ReturnObjDataset = ExecuteSQLQuery_ReturnDS(ReturnErrorMsg, SQlQuery, DbSQLConnString, DbType)
The connection would only be opened here:
Public Function ExecuteSQLQuery_ReturnDS(ByRef ReturnErrorMsg As String, ByVal SqlString As String, ByVal DBConnString As String, ByVal DBType As Int16) As DataSet
ReturnErrorMsg = ""
Dim DS As New DataSet
'
If DBType = 1 Then
Try
OpenConnection(DBConnString, DBType)
Dim sqlCmd As New SqlCommand(SqlString, sqlConn)
sqlCmd.CommandTimeout = 0
Dim sqlDaAdp As New SqlDataAdapter(sqlCmd)
sqlDaAdp.Fill(DS)
sqlCmd = Nothing
sqlDaAdp = Nothing
CloseConnection(DBType)
Return DS
Catch ex As SqlException
If ex.Number = 18456 Or ex.Number = 4060 Then
ReturnErrorMsg = "Database Connection Error >> Error No : " & ex.Number
Else
ReturnErrorMsg = "SQL Statement Error >> Error No : " & ex.Number
End If
CloseConnection(DBType)
Return Nothing
End Try
ElseIf DBType = 3 Then
Try
OpenConnection(DBConnString, DBType)
Dim oledbCmd As New OleDbCommand(SqlString, oleDbconn)
Dim oledbDaAdp As New OleDbDataAdapter(oledbCmd)
oledbDaAdp.Fill(DS)
oledbDaAdp = Nothing
oledbDaAdp = Nothing
CloseConnection(DBType)
Return DS
Catch ex As OleDbException
If ex.ErrorCode = -2147217887 Then
ReturnErrorMsg = "Database Connection Error >> Error Code : " & ex.ErrorCode
Else
ReturnErrorMsg = "SQL Statement Error >> Error Code : " & ex.ErrorCode
End If
CloseConnection(DBType)
Return Nothing
End Try
End If
'
Return Nothing
'
End Function
Open connection method:
Public Sub OpenConnection(ByVal DBStrConn As String, ByVal DBType As Int16)
Try
If DBType = 1 Then
sqlConn = New SqlConnection(DBStrConn)
If sqlConn.State = ConnectionState.Closed Then
sqlConn.Open()
Else
sqlConn.Close()
sqlConn.Open()
End If
ElseIf DBType = 3 Then
oleDbconn = New OleDbConnection(DBStrConn)
If oleDbconn.State = ConnectionState.Closed Then
oleDbconn.Open()
Else
oleDbconn.Close()
oleDbconn.Open()
End If
End If
'
Catch ex As Exception
Throw
End Try
End Sub
End of edited part
Does anyone have any idea why does such exception would occur?
So far, I've done the following to actually try to debug this issue:
Restart IIS
Restart Application Pool
Recycle Application Pool (every 12 hours, 8 a.m. and 8 p.m. specifically)
Restart SQL Server Service
None of the above worked. But when I actually tried accessing the application from a specific floor in which is the Security Team floor, the application actually starts functioning as usual, and others could actually access the application as well.
Please help, I'm totally going out of my mind about this issue.
Does it have anything to do with my deployment method, iis configuration or programming, I'm willing to listen to suggestions.
Thanks for your time.

convert Date column to string / label if NOT IsDBNull

I am trying (much too long) to convert a DateTime column to a label.Text.
Various errors:
What am I missing?
drExpDatesRow = dtAllCompanies.Select("CompanyID = " + CompanyID.ToString())
Dim ls_ExpiresDateString As String
If (Not IsDBNull(drExpDatesRow("Expdate"))) Then
Date.TryParse(drExpDatesRow("Expdate").ToString(), ls_ExpiresDateString)
'ls_ExpiresDateString = ldt_ExpiresDate.ToString("MM/dd/yyyy")
lbl_ExpireDate.Text = ls_ExpiresDateString.ToString()
Else
lbl_ExpireDate.Text = ""
End If
System.InvalidCastException was unhandled Message=Conversion from
string "Expdate" to type 'Integer' is not valid.
Source=Microsoft.VisualBasic StackTrace:
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String
Value)
at zzz.winCompanyInfo.CompanyInfo_Load(Object sender, EventArgs e) in C:\inetpub\zzz.vb:line 638
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) InnerException:
System.FormatException
Message=Input string was not in a correct format.
Source=Microsoft.VisualBasic
StackTrace:
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String
Value, NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String
Value)
InnerException:
UPDATE** Added DataRow logic
When using TryParse use the same data type.
Dim drExpDatesRow = (From dr As DataRow In dtAllCompanies.Rows
Where dr("CompanyId").ToString =
CompanyID.ToString).FirstOrDefault
Dim ls_ExpiresDate As Date ' Date not String
If (Not drExpDatesRow Is Nothing) Then
If Date.TryParse(drExpDatesRow("Expdate").ToString(), ls_ExpiresDate)
lbl_ExpireDate.Text = ls_ExpiresDate.ToString()
End If
Else
lbl_ExpireDate.Text = ""
End If
You had multiple issues in your code. This one should take care of things for good
drExpDatesRow = dtAllCompanies.Select("CompanyID = " + CompanyID.ToString()) ' returns array
lbl_ExpireDate.Text = ""
If drExpDatesRow.Length > 0 Then
If (Not IsDBNull(drExpDatesRow(0)("Expdate"))) Then
Dim myDate As DateTime
Dim res As Boolean = Date.TryParse(drExpDatesRow("Expdate"), myDate)
If res Then lbl_ExpireDate.Text = MyDate.ToString("<format>")
End If
End If

SAP Catching Data with RFC_CALL_TRANSACTION RFC VB

I become an errorcode 1001, an SAP Remote error?
I've googled alot but didn't find anything.
Maybe someone knows whats the Problem here.
Im using SAP 720.
System.Runtime.InteropServices.COMException (0x000003E9): SAP Remote
Function Call bei
Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o,
Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack) bei
Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack) ...
Here is my code:
Public FunctionCtrl As Object
Function login_Call()
Try
Dim conn As Object
FunctionCtrl = CreateObject("SAP.Functions")
conn = FunctionCtrl.Connection
conn.System = XXX
conn.ApplicationServer = XXX
conn.SystemNumber = XXX
conn.Client = "XXX"
conn.user = XXX
conn.Password = XXX
conn.Language = XXX
'needed for frontend dialog
conn.RfcWithDialog = True
'log on with logon dialog
If Not conn.Logon(0, 1) Then
Dim WsShell
Dim intText As Integer
WsShell = CreateObject("WScript.Shell")
intText = WsShell.Popup("Logon not succesful." & vbCrLf & _
"will be closed automatically in one minute...", 60)
'conn = Nothing
Anmeldung_Call = False
Exit Function
End If
Anmeldung_Call = True
Catch ex As Exception
Anmeldung_Call = False
End Try
Me.Text = DateTime.Now.ToString()
End Function
Sub Open_IW73()
Dim BdcTable As Object
Dim RfcCallTransaction As Object
Dim Messages As Object
Dim count As Integer
'call transaction IW73
RfcCallTransaction = FunctionCtrl.Add("RFC_CALL_TRANSACTION")
RfcCallTransaction.Exports("TRANCODE") = "IW73"
RfcCallTransaction.Exports("UPDMODE") = "S"
BdcTable = RfcCallTransaction.Tables("BDCTABLE").....
The Error comes in this line: "RfcCallTransaction = FunctionCtrl.Add("RFC_CALL_TRANSACTION")
"
Thank you
I've had the same error. People suggested different fixes like using SAP.functions.Unicode.
What did it for me was simply changing to "RFC_CALL_TRANSACTION_USING". I'm not sure of the exact difference between these commands, so be careful with that. So far it has been working for me though.