473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help Needed. Update with parameters error - No value given for one or more parameters.

Hello All,

Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in
my update statement and when trying to update a record, I get a "No value given for one or more parameters." error message.

I use a Select with parameters and an Update with parameters. The select works fine. I thought I've tried everything (evidently not) to get this
working. Please show me the errors of my ways or a different way to solve. I purposely want to create the da, dt, cn, etc. in code so I will get
used to them.

Thanks,

Hexman

Here's the excerpt of the failing code. (dtRES contains the transactions to update dtCN. The index variables (I & Idx) are correct in their values.
Private cnCN As OleDbConnection
Private CNQrySel As String
Private CNQryAdd As String
Private CNQryUpd As String
Private CNQryDel As String
Private CNCount As Integer
Dim dtCN As New DataTable
Dim daCN As New OleDbDataAdapter
Dim cmbCN As New OleDbCommandBuilder(daCN)

CNQrySel = "Select CNDate,CNPart,CNLoc,CNDesc,CNAmt,CNValue " & _
"FROM CNMaster " & _
"WHERE (CNDate = ? and CNPart = ? and CNLoc = ?) ; "
CNQryAdd = " ; "
CNQryDel = " ; "
CNQryUpd = "UPDATE CNMaster " & _
"SET @CNDesc = ?, @CNAmt = ?, @CNValue = ?" & _
"WHERE (CNDate = ? and CNPart = ? and CNLoc = ?) ; "
' Create the SelectCommand and parameters.
daCN.SelectCommand = New OleDbCommand(CNQrySel, cnCN)
daCN.SelectCommand.Parameters.Add("CNDate", OleDbType.Date, 8)
daCN.SelectCommand.Parameters.Add("CNPart", OleDbType.VarChar, 15)
daCN.SelectCommand.Parameters.Add("CNLoc", OleDbType.VarChar, 6)
' Create the UpdateCommand and parameters.
daCN.UpdateCommand = New OleDbCommand(CNQryUpd, cnCN)
daCN.UpdateCommand.Parameters.Add("@CNDesc", OleDbType.VarChar, 25, "CNDesc")
daCN.UpdateCommand.Parameters.Add("@CNAmt", OleDbType.Single, 4, "CNAmt")
daCN.UpdateCommand.Parameters.Add("@CNValue", OleDbType.Single, 4, "CNValue")
daCN.UpdateCommand.Parameters.Add("@CNDate", OleDbType.Date, 8, "CNDate")
daCN.UpdateCommand.Parameters.Add("@CNPart", OleDbType.VarChar, 15, "CNPart")
daCN.UpdateCommand.Parameters.Add("@CNLoc", OleDbType.VarChar, 6, "CNLoc")

cnCN.Open()

daCN.SelectCommand.Parameters("CNDate").Value = dtRES.Rows(Idx).Item("STDate")
daCN.SelectCommand.Parameters("CNPart").Value = dtRES.Rows(Idx).Item("STPart")
daCN.SelectCommand.Parameters("CNLoc").Value = dtRES.Rows(Idx).Item("STLoc")
CNCount = daCN.Fill(dtCN)

daCN.UpdateCommand.Parameters("@CNDesc").Value = dtRES.Rows(Idx).Item("STDesc")
daCN.UpdateCommand.Parameters("@CNAmt").Value = dtRES.Rows(Idx).Item("STAmt")
daCN.UpdateCommand.Parameters("@CNValue").Value = dtRES.Rows(Idx).Item("STValue")
daCN.UpdateCommand.Parameters("@CNDate").Value = dtRES.Rows(Idx).Item("STDate")
daCN.UpdateCommand.Parameters("@CNPart").Value = dtRES.Rows(Idx).Item("STPart")
daCN.UpdateCommand.Parameters("@CNLoc").Value = dtRES.Rows(Idx).Item("STLoc")

dtCN.Rows(I).Item("CNDate") = dtRES.Rows(Idx).Item("STDate")
dtCN.Rows(I).Item("CNPart") = dtRES.Rows(Idx).Item("STPart")
dtCN.Rows(I).Item("CNLoc") = dtRES.Rows(Idx).Item("STLoc")
dtCN.Rows(I).Item("CNDesc") = dtRES.Rows(Idx).Item("STDesc")
dtCN.Rows(I).Item("CNAmt") = dtRES.Rows(Idx).Item("STAmt")
dtCN.Rows(I).Item("CNValue") = dtRES.Rows(Idx).Item("STValue")

Try
daCN.Update(dtCN)
Catch ex As Exception
'An exception occurred
MsgBox(ex.ToString)
End Try
dtCN.AcceptChanges()

cnCN.Close()
Aug 10 '06 #1
2 2603
Hexman,

AFAIK does OleDB despite of the given samples on MSDN not use named
parameters.
>daCN.SelectCommand.Parameters.Add("CNDate", OleDbType.Date, 8)
this is valid as well
daCN.SelectCommand.Parameters.Add("", OleDbType.Date, 8)

Maybe you can change your names in the setting and adding of the values to
the parameters to 0 to 5.

If it is than still not working: I once had your problem as well. I added an
extra parameter as a kind of dummy and the problem was gone. I never
investigated the reason.

I hope this helps,

Cor

"Hexman" <He****@Binary.comschreef in bericht
news:4o********************************@4ax.com...
Hello All,

Well I'm stumped once more. Need some help. Writing a simple select and
update program using VB.Net 2005 and an Access DB. I'm using parameters in
my update statement and when trying to update a record, I get a "No value
given for one or more parameters." error message.

I use a Select with parameters and an Update with parameters. The select
works fine. I thought I've tried everything (evidently not) to get this
working. Please show me the errors of my ways or a different way to
solve. I purposely want to create the da, dt, cn, etc. in code so I will
get
used to them.

Thanks,

Hexman

Here's the excerpt of the failing code. (dtRES contains the transactions
to update dtCN. The index variables (I & Idx) are correct in their
values.
Private cnCN As OleDbConnection
Private CNQrySel As String
Private CNQryAdd As String
Private CNQryUpd As String
Private CNQryDel As String
Private CNCount As Integer
Dim dtCN As New DataTable
Dim daCN As New OleDbDataAdapter
Dim cmbCN As New OleDbCommandBuilder(daCN)

CNQrySel = "Select CNDate,CNPart,CNLoc,CNDesc,CNAmt,CNValue " & _
"FROM CNMaster " & _
"WHERE (CNDate = ? and CNPart = ? and CNLoc = ?) ; "
CNQryAdd = " ; "
CNQryDel = " ; "
CNQryUpd = "UPDATE CNMaster " & _
"SET @CNDesc = ?, @CNAmt = ?, @CNValue = ?" & _
"WHERE (CNDate = ? and CNPart = ? and CNLoc = ?) ; "
' Create the SelectCommand and parameters.
daCN.SelectCommand = New OleDbCommand(CNQrySel, cnCN)
daCN.SelectCommand.Parameters.Add("CNDate", OleDbType.Date, 8)
daCN.SelectCommand.Parameters.Add("CNPart", OleDbType.VarChar, 15)
daCN.SelectCommand.Parameters.Add("CNLoc", OleDbType.VarChar, 6)
' Create the UpdateCommand and parameters.
daCN.UpdateCommand = New OleDbCommand(CNQryUpd, cnCN)
daCN.UpdateCommand.Parameters.Add("@CNDesc", OleDbType.VarChar, 25,
"CNDesc")
daCN.UpdateCommand.Parameters.Add("@CNAmt", OleDbType.Single, 4, "CNAmt")
daCN.UpdateCommand.Parameters.Add("@CNValue", OleDbType.Single, 4,
"CNValue")
daCN.UpdateCommand.Parameters.Add("@CNDate", OleDbType.Date, 8, "CNDate")
daCN.UpdateCommand.Parameters.Add("@CNPart", OleDbType.VarChar, 15,
"CNPart")
daCN.UpdateCommand.Parameters.Add("@CNLoc", OleDbType.VarChar, 6, "CNLoc")

cnCN.Open()

daCN.SelectCommand.Parameters("CNDate").Value =
dtRES.Rows(Idx).Item("STDate")
daCN.SelectCommand.Parameters("CNPart").Value =
dtRES.Rows(Idx).Item("STPart")
daCN.SelectCommand.Parameters("CNLoc").Value =
dtRES.Rows(Idx).Item("STLoc")
CNCount = daCN.Fill(dtCN)

daCN.UpdateCommand.Parameters("@CNDesc").Value =
dtRES.Rows(Idx).Item("STDesc")
daCN.UpdateCommand.Parameters("@CNAmt").Value =
dtRES.Rows(Idx).Item("STAmt")
daCN.UpdateCommand.Parameters("@CNValue").Value =
dtRES.Rows(Idx).Item("STValue")
daCN.UpdateCommand.Parameters("@CNDate").Value =
dtRES.Rows(Idx).Item("STDate")
daCN.UpdateCommand.Parameters("@CNPart").Value =
dtRES.Rows(Idx).Item("STPart")
daCN.UpdateCommand.Parameters("@CNLoc").Value =
dtRES.Rows(Idx).Item("STLoc")

dtCN.Rows(I).Item("CNDate") = dtRES.Rows(Idx).Item("STDate")
dtCN.Rows(I).Item("CNPart") = dtRES.Rows(Idx).Item("STPart")
dtCN.Rows(I).Item("CNLoc") = dtRES.Rows(Idx).Item("STLoc")
dtCN.Rows(I).Item("CNDesc") = dtRES.Rows(Idx).Item("STDesc")
dtCN.Rows(I).Item("CNAmt") = dtRES.Rows(Idx).Item("STAmt")
dtCN.Rows(I).Item("CNValue") = dtRES.Rows(Idx).Item("STValue")

Try
daCN.Update(dtCN)
Catch ex As Exception
'An exception occurred
MsgBox(ex.ToString)
End Try
dtCN.AcceptChanges()

cnCN.Close()

Aug 10 '06 #2
Cor,

Thanks for the response. I changed my code to use positional parameters, but to no avail. But your message made me dig a bit deeper and i found my
answer at: ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_raddata/html/195e0209-68d4-4e86-8a3b-f0d2f14332d8.htm

After reading about the update parameters I saw the error in my code. I changed :
>>CNQryUpd = "UPDATE CNMaster " & _
"SET @CNDesc = ?, @CNAmt = ?, @CNValue = ?" & _
"WHERE (CNDate = ? and CNPart = ? and CNLoc = ?) ; "
to this:
>>CNQryUpd = "UPDATE CNMaster " & _
"SET CNDesc = ?, CNAmt = ?, CNValue = ?" & _
"WHERE (CNDate = ? and CNPart = ? and CNLoc = ?) ; "
Apparently I was setting the parameter (@CNDesc) to the same parameter rather than setting the column(CNDesc) to the parameter (@CNDesc).

Solved my problem. Although after reading I have more questions. I'll start a new thread for each on so they can be focused on.

Thanks,

Hexman

On Thu, 10 Aug 2006 07:31:12 +0200, "Cor Ligthert [MVP]" <no************@planet.nlwrote:
>Hexman,

AFAIK does OleDB despite of the given samples on MSDN not use named
parameters.
>>daCN.SelectCommand.Parameters.Add("CNDate", OleDbType.Date, 8)
this is valid as well
daCN.SelectCommand.Parameters.Add("", OleDbType.Date, 8)

Maybe you can change your names in the setting and adding of the values to
the parameters to 0 to 5.

If it is than still not working: I once had your problem as well. I added an
extra parameter as a kind of dummy and the problem was gone. I never
investigated the reason.

I hope this helps,

Cor

"Hexman" <He****@Binary.comschreef in bericht
news:4o********************************@4ax.com.. .
>Hello All,

Well I'm stumped once more. Need some help. Writing a simple select and
update program using VB.Net 2005 and an Access DB. I'm using parameters in
my update statement and when trying to update a record, I get a "No value
given for one or more parameters." error message.

I use a Select with parameters and an Update with parameters. The select
works fine. I thought I've tried everything (evidently not) to get this
working. Please show me the errors of my ways or a different way to
solve. I purposely want to create the da, dt, cn, etc. in code so I will
get
used to them.

Thanks,

Hexman

Here's the excerpt of the failing code. (dtRES contains the transactions
to update dtCN. The index variables (I & Idx) are correct in their
values.
Private cnCN As OleDbConnection
Private CNQrySel As String
Private CNQryAdd As String
Private CNQryUpd As String
Private CNQryDel As String
Private CNCount As Integer
Dim dtCN As New DataTable
Dim daCN As New OleDbDataAdapter
Dim cmbCN As New OleDbCommandBuilder(daCN)

CNQrySel = "Select CNDate,CNPart,CNLoc,CNDesc,CNAmt,CNValue " & _
"FROM CNMaster " & _
"WHERE (CNDate = ? and CNPart = ? and CNLoc = ?) ; "
CNQryAdd = " ; "
CNQryDel = " ; "
CNQryUpd = "UPDATE CNMaster " & _
"SET @CNDesc = ?, @CNAmt = ?, @CNValue = ?" & _
"WHERE (CNDate = ? and CNPart = ? and CNLoc = ?) ; "
' Create the SelectCommand and parameters.
daCN.SelectCommand = New OleDbCommand(CNQrySel, cnCN)
daCN.SelectCommand.Parameters.Add("CNDate", OleDbType.Date, 8)
daCN.SelectCommand.Parameters.Add("CNPart", OleDbType.VarChar, 15)
daCN.SelectCommand.Parameters.Add("CNLoc", OleDbType.VarChar, 6)
' Create the UpdateCommand and parameters.
daCN.UpdateCommand = New OleDbCommand(CNQryUpd, cnCN)
daCN.UpdateCommand.Parameters.Add("@CNDesc", OleDbType.VarChar, 25,
"CNDesc")
daCN.UpdateCommand.Parameters.Add("@CNAmt", OleDbType.Single, 4, "CNAmt")
daCN.UpdateCommand.Parameters.Add("@CNValue", OleDbType.Single, 4,
"CNValue")
daCN.UpdateCommand.Parameters.Add("@CNDate", OleDbType.Date, 8, "CNDate")
daCN.UpdateCommand.Parameters.Add("@CNPart", OleDbType.VarChar, 15,
"CNPart")
daCN.UpdateCommand.Parameters.Add("@CNLoc", OleDbType.VarChar, 6, "CNLoc")

cnCN.Open()

daCN.SelectCommand.Parameters("CNDate").Value =
dtRES.Rows(Idx).Item("STDate")
daCN.SelectCommand.Parameters("CNPart").Value =
dtRES.Rows(Idx).Item("STPart")
daCN.SelectCommand.Parameters("CNLoc").Value =
dtRES.Rows(Idx).Item("STLoc")
CNCount = daCN.Fill(dtCN)

daCN.UpdateCommand.Parameters("@CNDesc").Value =
dtRES.Rows(Idx).Item("STDesc")
daCN.UpdateCommand.Parameters("@CNAmt").Value =
dtRES.Rows(Idx).Item("STAmt")
daCN.UpdateCommand.Parameters("@CNValue").Value =
dtRES.Rows(Idx).Item("STValue")
daCN.UpdateCommand.Parameters("@CNDate").Value =
dtRES.Rows(Idx).Item("STDate")
daCN.UpdateCommand.Parameters("@CNPart").Value =
dtRES.Rows(Idx).Item("STPart")
daCN.UpdateCommand.Parameters("@CNLoc").Value =
dtRES.Rows(Idx).Item("STLoc")

dtCN.Rows(I).Item("CNDate") = dtRES.Rows(Idx).Item("STDate")
dtCN.Rows(I).Item("CNPart") = dtRES.Rows(Idx).Item("STPart")
dtCN.Rows(I).Item("CNLoc") = dtRES.Rows(Idx).Item("STLoc")
dtCN.Rows(I).Item("CNDesc") = dtRES.Rows(Idx).Item("STDesc")
dtCN.Rows(I).Item("CNAmt") = dtRES.Rows(Idx).Item("STAmt")
dtCN.Rows(I).Item("CNValue") = dtRES.Rows(Idx).Item("STValue")

Try
daCN.Update(dtCN)
Catch ex As Exception
'An exception occurred
MsgBox(ex.ToString)
End Try
dtCN.AcceptChanges()

cnCN.Close()
Aug 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
by: AxleWacl | last post by:
Hi, The below error is what I am receiving. The code im using is below the error, for the life of me, I can not see where any parameter is missing..... Server Error in '/FleetcubeNews'...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.