cmd.Parameters.Add(new OleDbParameter NOT TAKING ???

J

jason

Hello,


I can't get the below update to work. Here's what I know..
If I enter fixed strings in the update it works. The response.write
displays show good and updated values in the s strings. However, only
the @chain cmd.Param gets set, all others,like @responsible either
never get set or remain as they were. Strangley, I have this code in
another subroutine whree I'm adding a brand new record and it works
fine. I've copied the block of working text in and view the source in
hex and everything looks fine. I need another pair of eyes.

THANK YOU.


Public Sub UserGrid_Update (Source As Object, E As
DataGridCommandEventArgs)
Dim objConn as new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=x.mdb")

Dim cmd As OleDbCommand = new OleDbCommand ("UPDATE tbl SET
status=@status, responsible=@responsible WHERE chain=@chain", objConn)

Dim schain As String = e.Item.Cells(2).Text
Dim sresponsible As String = CType(e.Item.Cells(3).Controls (0),
TextBox).Text
Dim sstatus As String = CType(e.Item.Cells(4).Controls (0),
TextBox).Text
Dim swaitingon As String = CType(e.Item.Cells(5).Controls (0),
TextBox).Text
Dim scomments As String = CType(e.Item.Cells(6).Controls (0),
TextBox).Text


response.write(schain+"-"+sresponsible+"-"+sstatus+"-"+swaitingon+"-"+scomments)

cmd.Parameters.Add(new OleDbParameter("@chain", schain))
cmd.Parameters.Add(new OleDbParameter("@responsible",
sresponsible))
cmd.Parameters.Add(new OleDbParameter("@status", sstatus))
cmd.Parameters.Add(new OleDbParameter("@waitingon", swaitingon))

cmd.Parameters.Add(new OleDbParameter("@comments", scomments))


objConn.Open()
cmd.ExecuteNonQuery()
objConn.Close

' UserGrid.EditItemIndex = -1
BindData()



End Sub
 
M

Miha Markic [MVP C#]

Hi Jason,

Try using question marks (?) instead of @name in sql statement and make sure
you set parameters in same order.
 
J

jason

Miha said:
... make sure you set parameters in same order.


BINGO! I did not realize that mattered since names are defined, but it
does. What's funny is how in all my testing combination the order
(though changing) never matched. Thank you very much.
 
S

Scott M.

Nope. The @ symbol is the correct symbol to use.


Miha Markic said:
Hi Jason,

Try using question marks (?) instead of @name in sql statement and make
sure you set parameters in same order.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

Hello,


I can't get the below update to work. Here's what I know..
If I enter fixed strings in the update it works. The response.write
displays show good and updated values in the s strings. However, only
the @chain cmd.Param gets set, all others,like @responsible either
never get set or remain as they were. Strangley, I have this code in
another subroutine whree I'm adding a brand new record and it works
fine. I've copied the block of working text in and view the source in
hex and everything looks fine. I need another pair of eyes.

THANK YOU.


Public Sub UserGrid_Update (Source As Object, E As
DataGridCommandEventArgs)
Dim objConn as new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=x.mdb")

Dim cmd As OleDbCommand = new OleDbCommand ("UPDATE tbl SET
status=@status, responsible=@responsible WHERE chain=@chain", objConn)

Dim schain As String = e.Item.Cells(2).Text
Dim sresponsible As String = CType(e.Item.Cells(3).Controls (0),
TextBox).Text
Dim sstatus As String = CType(e.Item.Cells(4).Controls (0),
TextBox).Text
Dim swaitingon As String = CType(e.Item.Cells(5).Controls (0),
TextBox).Text
Dim scomments As String = CType(e.Item.Cells(6).Controls (0),
TextBox).Text


response.write(schain+"-"+sresponsible+"-"+sstatus+"-"+swaitingon+"-"+scomments)

cmd.Parameters.Add(new OleDbParameter("@chain", schain))
cmd.Parameters.Add(new OleDbParameter("@responsible",
sresponsible))
cmd.Parameters.Add(new OleDbParameter("@status", sstatus))
cmd.Parameters.Add(new OleDbParameter("@waitingon", swaitingon))

cmd.Parameters.Add(new OleDbParameter("@comments", scomments))


objConn.Open()
cmd.ExecuteNonQuery()
objConn.Close

' UserGrid.EditItemIndex = -1
BindData()



End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top