I'm developing an OOB Silverlight application and using the COM Toolkit (http://silverlightcom.codeplex.com), the language is Visual Basic (VB). With this pack, I can connect my app with my Microsoft SQL Server database using ADO.NET. It works, but when I try to insert a null value to a parameter it throws an exception: 0x800A0BB9 (http://prntscr.com/43zwyr).
My code is (I will post the most simple stretch):
Private Const SqlCreateJob As String = "insert into Cargos(Nome_carg, Desc_carg) values(?, ?)"
Public Shared Sub CreateJob(ByVal j As Job)
Dim conn As AdoConnection = DbUtil.GetConn
Dim cmd As AdoCommand = conn.CreateCommand
cmd.CommandText = SqlCreateJob
cmd.Parameters.AddWithValue("Nome_carg", j.Name)
cmd.Parameters.AddWithValue("Desc_carg", j.Desc)
For Each p As AdoParameter In cmd.Parameters
If p.Value = Nothing Then
p.Value = DBNull.Value
End If
Next
cmd.ExecuteNonQuery()
conn.Close()
End Sub
And the class Job:
Public Class Job
Property Code() As Integer
Property Name() As String
Property Desc() As String
End Class
The value Desc, from Job, can be null. And if I put
cmd.Parameters.AddWithValue("Desc_carg", DBNull.Value) it still doesn't work. What can I do? (When the Desc is not null the command works)
The Exception.ToString is here:
System.Runtime.InteropServices.COMException (0x800A0BB9): Exception from HRESULT: 0x800A0BB9 ---> MS.Internal.ComAutomation.ComAutomationObjectException: The arguments are incorrect, are out of acceptable range, or are in conflict.(Source=ADODB.Parameter) (HelpFile=C:\WINDOWS\HELP\ADO270.CHM#1240641) em MS.Internal.ComAutomation.ComAutomationNative.CheckInvokeHResult(UInt32 hr, String memberName, String exceptionSource, String exceptionDescription, String exceptionHelpFile, UInt32 exceptionHelpContext) em MS.Internal.ComAutomation.ComAutomationNative.Invoke(Boolean tryInvoke, String memberName, ComAutomationInvokeType invokeType, ComAutomationInteropValue[] rgParams, IntPtr nativePeer, ComAutomationInteropValue& returnValue) em MS.Internal.ComAutomation.ComAutomationObject.InvokeImpl(Boolean tryInvoke, String name, ComAutomationInvokeType invokeType, Object& returnValue, Object[] args) em MS.Internal.ComAutomation.ComAutomationObject.Invoke(String name, ComAutomationInvokeType invokeType, Object[] args) em System.Runtime.InteropServices.Automation.AutomationMetaObjectProvider.TrySetMember(SetMemberBinder binder, Object value) em System.Runtime.InteropServices.Automation.AutomationMetaObjectProviderBase.<.cctor>b__3(Object obj, SetMemberBinder binder, Object value) em CallSite.Target(Closure , CallSite , Object , Int32 ) em System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) em CallSite.Target(Closure , CallSite , Object , Int32 ) em ComToolkit.Data.AdoParameter.set_Type(DbType value) em ComToolkit.Data.AdoParameter..ctor(Object adoParameter, String name, Object value) em CallSite.Target(Closure , CallSite , Type , Object , String , Object ) em System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3) em CallSite.Target(Closure , CallSite , Type , Object , String , Object ) em ComToolkit.Data.AdoCommand.CreateParameter(String name, Object value) em ComToolkit.Data.AdoParameterCollection.AddWithValue(String name, Object value) em Corporativo.Dao.CargoDao.AddParameters(AdoCommand cmd, Cargo c) em Corporativo.Dao.CargoDao.CriarCargo(Cargo c) em Corporativo.UCCadCargos.Create()
And the .Message:
Exception from HRESULT: 0x800A0BB9
You should not be using AddWithValue if the value is, or van be, NULL. AddWithValue infers the data type of the parameter from the value but, if the value is NULL, a type cannot be inferred. You should be using Add in such cases, specifying the data type explicitly and setting the Value property.
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
I work on a VB.NET project, and I have a button that I want to insert data to my table with. So this is the code of this button :
Public Class Form21
Dim connexion As New SqlCeConnection("Data Source=D:\Cours\Projets\Stge\WindowsApplication1\WindowsApplication1\datababse.sdf")
Dim cmd As New SqlCeCommand
Dim libelle As String = TextBox1.Text
Dim prix As Double = Double.Parse(TextBox2.Text)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cmd.Connection = connexion
cmd.CommandText = "INSERT into Produit_fini values(#libelle,#prix)"
cmd.Parameters.AddWithValue("#libelle", libelle)
cmd.Parameters.AddWithValue("#prix", prix)
connexion.Open()
cmd.ExecuteNonQuery()
connexion.Close()
End Sub
End Class
The problem now, is that when I want to open the window where the button is figured, I get an error on this line :
Form21.ShowDialog()
The error says that I cannot open the window. Are there any errors in my button's code? Please help.
Thank you
Here is the error detail :
L'exception System.InvalidOperationException n'a pas été gérée
Message=Une erreur s'est produite lors de la création du formulaire. Pour plus d'informations, consultez Exception.InnerException. L'erreur est : La référence d'objet n'est pas définie à une instance d'un objet.
Source=database
StackTrace:
à database.My.MyProject.MyForms.Create_Instance_[T](T Instance) dans 17d14f5c-a337-4978-8281-53493378c1071.vb:ligne 190
à database.My.MyProject.MyForms.get_Form21()
à database.Form1.إضافةمنتوججديدToolStripMenuItem_Click(Object sender, EventArgs e) dans D:\Cours\Projets\ferran\WindowsApplication1\WindowsApplication1\Form1.vb:ligne 130
à System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
à System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
à System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
à System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
à System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
à System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
à System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
à System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
à System.Windows.Forms.Control.WndProc(Message& m)
à System.Windows.Forms.ScrollableControl.WndProc(Message& m)
à System.Windows.Forms.ToolStrip.WndProc(Message& m)
à System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.Run(ApplicationContext context)
à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
à database.My.MyApplication.Main(String[] Args) dans 17d14f5c-a337-4978-8281-53493378c1071.vb:ligne 81
à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
InnerException: System.NullReferenceException
Message=La référence d'objet n'est pas définie à une instance d'un objet.
Source=database
StackTrace:
à database.Form21..ctor() dans D:\Cours\Projets\Stge\WindowsApplication1\WindowsApplication1\Form21.vb:ligne 7
Public Class Form21
Dim connexion As New SqlCeConnection("Data Source...")
Dim cmd As New SqlCeCommand
Dim libelle As String = TextBox1.Text
Dim prix As Double = Double.Parse(TextBox2.Text)
If these are form level declares as they appear to be you cannot reference controls (TextBox1 and TextBox2) before they are initialized. Change to:
Dim libelle As String = ""
Dim prix As Double =
Then in Form Load (when the TBs exist):
libelle = TextBox1.Text
prix = Double.Parse(TextBox2.Text)
I just stopped by this error
System.NullReferenceException was unhandled HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=System.Windows.Forms StackTrace:
at System.Windows.Forms.RichTextBox.StreamIn(String str, Int32 flags)
at System.Windows.Forms.RichTextBox.set_SelectedText(String value)
at Novania_JAV_Viewer_EncDec.Form1.Button1_Click(Object sender, EventArgs ef) in c:\users\toshiba\documents\visual studio
2010\Projects\Novania JAV Viewer EncDec\Novania JAV Viewer
EncDec\Form1.vb:line 91
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(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)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine)
at Novania_JAV_Viewer_EncDec.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart() InnerException:
and this is my whole code, I am trying to replace all alphabet in one word, and it needs to replace one by one, and one by one variable.
the error is located here ("title") word
Do Until RichTextBox1.Find("titelz") = -1
RichTextBox1.Find("titelz")
RichTextBox1.SelectedText = titel
and this is my whole form class code
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RichTextBox1.LoadFile("template.rtf")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal ef As System.EventArgs) Handles Button1.Click
Dim A As String
Replace(TextBox1.Text, "A", "5TY5")
Console.WriteLine(A)
Dim B As String
Replace(A, "B", "WEE")
Console.WriteLine(B)
Dim C As String
Replace(B, "C", "23RW")
Console.WriteLine(C)
Dim D As String
Replace(C, "D", "RW4R")
Console.WriteLine(D)
Dim E As String
Replace(D, "E", "DFS")
Console.WriteLine(E)
Dim F As String
Replace(E, "F", "R5")
Console.WriteLine(F)
Dim G As String
Replace(F, "G", "QWEDQ")
Console.WriteLine(G)
Dim H As String
Replace(G, "H", "ZDCZ")
Console.WriteLine(H)
Dim I As String
Replace(H, "I", "VGHN")
Console.WriteLine(I)
Dim J As String
Replace(I, "J", "ZSC")
Console.WriteLine(J)
Dim K As String
Replace(J, "K", "ZSD")
Console.WriteLine(K)
Dim L As String
Replace(K, "L", "WER")
Console.WriteLine(L)
Dim M As String
Replace(L, "M", "GN")
Console.WriteLine(M)
Dim N As String
Replace(M, "N", "xfv")
Console.WriteLine(N)
Dim O As String
Replace(N, "O", "DAASAD")
Console.WriteLine(O)
Dim P As String
Replace(O, "P", "WET")
Console.WriteLine(P)
Dim Q As String
Replace(P, "Q", "DFCV")
Console.WriteLine(Q)
Dim R As String
Replace(Q, "R", "ADSDA")
Console.WriteLine(R)
Dim S As String
Replace(R, "S", "SGFDG")
Console.WriteLine(S)
Dim T As String
Replace(S, "T", "SFSFD")
Console.WriteLine(T)
Dim U As String
Replace(T, "U", "AWDAD")
Console.WriteLine(U)
Dim V As String
Replace(U, "V", "RERE")
Console.WriteLine(V)
Dim W As String
Replace(V, "W", "GBGDBB")
Console.WriteLine(W)
Dim X As String
Replace(W, "X", " AWDAW ")
Console.WriteLine(X)
Dim Y As String
Replace(X, "Y", "AWDEAVA")
Console.WriteLine(Y)
Dim Z As String
Replace(Y, "Z", "AWEDWADW")
Console.WriteLine(Z)
Dim titel As String = Z
Do Until RichTextBox1.Find("titelz") = -1
RichTextBox1.Find("titelz")
RichTextBox1.SelectedText = titel
Loop
RichTextBox2.Text = RichTextBox1.Text
RichTextBox1.Clear()
RichTextBox1.LoadFile("template.rtf")
End Sub
End Class
In order to do the replace, I'd try the following code...
It uses a Dictionary type variable. They are used in .NET quite a lot as some sort of associative array.
' First, create dictionary that you can loop through.
' This variable is created on form level (so only once)
' and contains all the "words" as key-value pairs.
' So you can search for key and replace with value.
Dim replaceDictionary As New Dictionary(Of String, String) From {{"A", "5TY5"}, _
{"B", "WEE"}, _
{"C", "23RW"}, _
{"D", "RW4R"}, _
{"E", "DFS"}, _
{"F", "R5"}, _
{"G", "QWEDQ"}, _
{"H", "ZDCZ"}, _
{"I", "VGHN"}, _
{"J", "ZSC"}, _
{"K", "ZSD"}, _
{"L", "WER"}, _
{"M", "GN"}, _
{"N", "xfv"}, _
{"O", "DAASAD"}, _
{"P", "WET"}, _
{"Q", "DFCV"}, _
{"R", "ADSDA"}, _
{"S", "SGFDG"}, _
{"T", "SFSFD"}, _
{"U", "AWDAD"}, _
{"V", "RERE"}, _
{"W", "GBGDBB"}, _
{"X", " AWDAW "}, _
{"Y", "AWDEAVA"}, _
{"Z", "AWEDWADW"}
}
Private Sub btnReplace_Click(sender As System.Object, e As System.EventArgs) Handles btnReplace.Click
' Declare temporary variable to store text
Dim tmpText As String = txtTitel.Text
' Loop through dictionary
For Each replaceItem In replaceDictionary
' Replace key ("A" etc.) with value ("5TY5" etc.)
' and store in temporary variable
tmpText = Replace(tmpText, replaceItem.Key, replaceItem.Value)
Next
'Display text
txtTitel.Text = tmpText
End Sub
Now for your "find" part... nothing like "titelz" is going to be changed with above code (only caps), so if it was in there, it stays in there.
So I have no idea what to do with that...
Edit
For the record: this goes for a long line of replaces... Once you've replaced all the A's in your string, the T from "5TY5" will also be replaced.
If you don't want this, you'll have to split the original text into characters and start checking them one by one.
Checking title string one letter at a time
There are a few changes to above code:
Dictionary is now of type (Char, String) instead of 2 strings.
The title is stored in a seperate variable in order to keep working with the orignal title text.
Instead of looping through the dictionary, you loop through the title text one letter at a time.
The code is documented with comments and should be pretty self-explanatory.
Good luck!
' First, create dictionary that you can loop through.
' This variable is created on form level (so only once)
' and contains all the "words" as key-value pairs.
' So you can search for key and replace with value.
Dim replaceDictionary As New Dictionary(Of Char, String) From {{"A", "5TY5"}, _
{"B", "WEE"}, _
{"C", "23RW"}, _
{"D", "RW4R"}, _
{"E", "DFS"}, _
{"F", "R5"}, _
{"G", "QWEDQ"}, _
{"H", "ZDCZ"}, _
{"I", "VGHN"}, _
{"J", "ZSC"}, _
{"K", "ZSD"}, _
{"L", "WER"}, _
{"M", "GN"}, _
{"N", "xfv"}, _
{"O", "DAASAD"}, _
{"P", "WET"}, _
{"Q", "DFCV"}, _
{"R", "ADSDA"}, _
{"S", "SGFDG"}, _
{"T", "SFSFD"}, _
{"U", "AWDAD"}, _
{"V", "RERE"}, _
{"W", "GBGDBB"}, _
{"X", " AWDAW "}, _
{"Y", "AWDEAVA"}, _
{"Z", "AWEDWADW"}
}
Private Sub btnReplace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplace.Click
' Declare temporary variable to store text
Dim tmpTitle As String = txtTitel.Text
Dim tmpText As String = ""
Dim tmpLetter As Char
' Loop through title string
Dim i As Integer = 0
Do While (i < tmpTitle.Length)
' Increase counter
i += 1
' Save next letter in tmpLetter
tmpLetter = Mid(tmpTitle, i, 1)
' Check for key in dictionary
If replaceDictionary.ContainsKey(tmpLetter) Then
' When found, append associated value to tmpText
tmpText &= replaceDictionary(tmpLetter)
Else
' Not found: use letter from title string
tmpText &= CStr(tmpLetter)
End If
Loop
'Display text
txtTitel.Text = tmpText
End Sub
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