Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my first time to use oracle as db. syntax are not the same. i try updating a certain column but it does not work.


DATA of the parameters:


VB
Public Con As New OracleConnection("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=XXX)(HOST=xxx.xxx.xx.xxx)(PORT=1521))(CONNECT_DATA = (SID = xxxx)));user id=xxx;Password=xxx;")
    

  Protected Sub btnShipment_Click(sender As Object, e As EventArgs) Handles btnShipment.Click

   Con.Close()
   Con.Open()
 For i As Integer = 0 To GridView1.Rows.Count - 1
       
Dim cmd As New OracleCommand("UPDATE PRODUCT SET  SHIP_REQUEST_NO = :shipreqno,  SHIP_DATE = :sd, SHIP_DATETIME = :sdt, PURCH_ORDER = :po, ORDER_NO = :od, UPDATE_DATE = :dd WHERE PACKAGE = :pn", Con) With {.CommandType = CommandType.Text, .BindByName = True}
         cmd .Parameters.Add(New OracleParameter("pn", GridView1.Rows(i).Cells(1).Text))
         cmd .Parameters.Add(New OracleParameter("sd", sds))
         cmd.Parameters.Add(New OracleParameter("sdt", dtime))
         cmd .Parameters.Add(New OracleParameter("po", pon))
         cmd .Parameters.Add(New OracleParameter("od", ord))
         cmd .Parameters.Add(New OracleParameter("shipreqno", GridView1.Rows(i).Cells(0).Text))
         cmd .Parameters.Add(New OracleParameter("dd", DateTime.Today.ToString("dd-MMM-yy"))) '
 cmd .ExecuteNonQuery()

Next



end sub



I tried this code below.still not working:

SQL
Dim query As String = "UPDATE PRODUCT SET ORDER_NO = :od  WHERE PACKING =  :pn"
            Dim command As OracleCommand = New OracleCommand(query, code.OCon) _
With {.CommandType = CommandType.Text, .BindByName = True}
            command.Parameters.Add("pn", OracleDbType.Varchar2).Value = packingnumber
            command.Parameters.Add("od", OracleDbType.Varchar2).Value = ordernum
Posted
Updated 29-Apr-15 14:47pm
v7
Comments
Jörgen Andersson 29-Apr-15 2:22am    
You're not stating if you get an error or not, nor in what way it isn't working.
Question: Is UPDATE_DATE a string in the database?
NekoNao 29-Apr-15 3:17am    
I don't get any error but that's the problem it does not give error but does not update.

no.its not. its date. i dont know how to coonvert it to date. with format of dd-MMM-yy [ex.14-APR-15]
Maciej Los 29-Apr-15 3:19am    
If it's a date, you don't need to convert it to string or format!
Jörgen Andersson 29-Apr-15 3:58am    
As Maciej wrote, you don't. Just use DateTime.Today directly.
What datatypes are SHIP_DATETIME and dtime?
Actually, can you list what datatypes your fields in PRODUCT is and also the datatypes of the corresponding parameters.
NekoNao 29-Apr-15 4:11am    
all of it has datatypes of varchar2 except from update_date which is date. but it needs a format of dd-MMM-yy [ex.14-APR-15] to be able to save.

The comments about date and [on] parameter are still active.

On the second look, you have to initiate OracleParameter using the name you used in command string. So, instead of:
VB
cmd .Parameters.Add(New OracleParameter("sd", sd))

use
VB
cmd .Parameters.Add(New OracleParameter(":sd", sd))


Have a look at first parameter of OracleParameter constructor! Do you see the difference?

Please, read this too: Gotcha #1161: Using Named Parameters with Oracle ODP.NET[^]
 
Share this answer
 
Comments
NekoNao 29-Apr-15 20:32pm    
I have tried that code but it does not work.
one thing that you can apply to solve your issue ,
if you pass where clause parameters at last then your query execute perfactly

as in this

VB
Dim query As String = "UPDATE PRODUCT SET ORDER_NO = :od  WHERE PACKING =  :pn"
            Dim command As OracleCommand = New OracleCommand(query, code.OCon) _
With {.CommandType = CommandType.Text, .BindByName = True}
            command.Parameters.Add("pn", OracleDbType.Varchar2).Value = packingnumber
            command.Parameters.Add("od", OracleDbType.Varchar2).Value = ordernum


Make this

VB
Dim query As String = "UPDATE PRODUCT SET ORDER_NO = :od  WHERE PACKING =  :pn"
            Dim command As OracleCommand = New OracleCommand(query, code.OCon) _
With {.CommandType = CommandType.Text, .BindByName = True}
            command.Parameters.Add(":od", OracleDbType.Varchar2).Value = ordernum
command.Parameters.Add(":pn", OracleDbType.Varchar2).Value = packingnumber


Then it's work 100% , please try
 
Share this answer
 
Comments
Shivaprasad Rao 6-Nov-22 21:06pm    
BindByName = True did the trick for me, thanks a lot Praveen!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900