.NETGURU
OleDbParameters
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-oledb' list.


Kilgo, John (alt)
I'm working my way through a book on .NET, specifically ADO.Net. There is
an example of updating a table with the data displayed in a datagrid, with
an "Edit" link button. This allows certain columns on any row to be
updated. The example works when connecting to SQL Server using the
SqlClient namespace. I, however, (for reasons I won't go into) must make it
work with OleDb instead. The problem is I receive the error:
System.Data.OleDb.OleDbException: Must declare the variable '@productName'.

A code snippet follows. Any help will be appreciated!

' Update Database
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim sqlString As String

myConnection = New OledbConnection("Provider=blah;blah;blah;)
sqlString = "Update Products Set ProductName = " &
"@productName, UnitPrice = @unitPrice WHERE ProductID=@productID"
myCommand = New OleDbCommand( sqlString, myConnection)
myCommand.Parameters.Add (New OleDbParameter ("@ProductName",
OleDbType.VarChar, 80))
myCommand.Parameters("@ProductName").Value = productName.Text
myCommand.Parameters.Add (New OleDbParameter("@unitPrice",
OleDbType.currency))
myCommand.Parameters("@unitPrice").Value = cType(unitPrice.Text, Decimal)
myCommand.Parameters.Add (New OleDbParameter ("@productID",
OleDbType.Integer))
myCommand.Parameters("@productID").Value =
myDataGrid.DataKeys.Item(e.Item.ItemIndex)
myConnection.Open()
myCommand.ExecuteNonQuery <==== Error occurs here
myConnection.Close()
myDataGrid.EditItemIndex = -1
BindData

Thanks for any help,

John Kilgo
Brandt Information Services, Inc.
Click here to reveal e-mail address
(850) 877-7713 ext. 554

Reply to this message...
 
    
Chang, Hsienyuan Grace
Try the variable said productName without the '@' in the front.

Best,
Grace Chang

-----Original Message-----
From: Kilgo, John (alt) [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 23, 2002 9:53 AM
To: ngfx-oledb
Subject: [ngfx-oledb] OleDbParameters

I'm working my way through a book on .NET, specifically ADO.Net. There is
an example of updating a table with the data displayed in a datagrid, with
an "Edit" link button. This allows certain columns on any row to be
updated. The example works when connecting to SQL Server using the
SqlClient namespace. I, however, (for reasons I won't go into) must make it
work with OleDb instead. The problem is I receive the error:
System.Data.OleDb.OleDbException: Must declare the variable '@productName'.

A code snippet follows. Any help will be appreciated!

' Update Database
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim sqlString As String

myConnection = New OledbConnection("Provider=blah;blah;blah;)
sqlString = "Update Products Set ProductName = " &
"@productName, UnitPrice = @unitPrice WHERE ProductID=@productID"
myCommand = New OleDbCommand( sqlString, myConnection)
myCommand.Parameters.Add (New OleDbParameter ("@ProductName",
OleDbType.VarChar, 80)) myCommand.Parameters("@ProductName").Value =
productName.Text myCommand.Parameters.Add (New OleDbParameter("@unitPrice",
OleDbType.currency))
myCommand.Parameters("@unitPrice").Value = cType(unitPrice.Text, Decimal)
myCommand.Parameters.Add (New OleDbParameter ("@productID",
OleDbType.Integer))
myCommand.Parameters("@productID").Value =
myDataGrid.DataKeys.Item(e.Item.ItemIndex)
myConnection.Open()
myCommand.ExecuteNonQuery <==== Error occurs here
myConnection.Close()
myDataGrid.EditItemIndex = -1
BindData

Thanks for any help,

John Kilgo
Brandt Information Services, Inc.
Click here to reveal e-mail address
(850) 877-7713 ext. 554

| [ngfx-oledb] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-oledb.asp = JOIN/QUIT

Reply to this message...
 
    
k.Sanjeev kumar
(Type your message here)

--------------------------------
From: k.Sanjeev kumar

Hi try like this
remove @parameter and keep ? marks

string StrUpdateQuery = "Update Sur_User set Register_Date='?',User_Password='?',Password_Hint='?',First_Name='?',Last_Name='?',Email_Address='?'";
                StrUpdateQuery=StrUpdateQuery + " Current_Position='?',Company='?',Location='?',Custom_Data_1='?',Custom_Data_2='?',Custom_Data_3='?',Active_YN='?',Role_ID='?' where User_ID=? ";
                OleDbParameter[] arrParam = {            
                                                new OleDbParameter("PUserID",UserID),
                                                //new OleDbParameter("PUserName", UserName),
                                                new OleDbParameter("PRegisterDate",RegisterDate),
                                                new OleDbParameter("PUserPassword", UserPassword),
                                                new OleDbParameter("PPasswordHint",PasswordHint),
                                                new OleDbParameter("PFirstName",FirstName),
                                                new OleDbParameter("PLastName",LastName),
                                                new OleDbParameter("PEmailAddress", EmailAddress),
                                                new OleDbParameter("PCurrentPosition",CurrentPosition),
                                                new OleDbParameter("PCompany", Company),
                                                new OleDbParameter("PLocation",Location),
                                                new OleDbParameter("PCustomData1",CustomData1),
                                                new OleDbParameter("PCustomData2",CustomData2),
                                                new OleDbParameter("PCustomData3",CustomData3),
                                                new OleDbParameter("PActiveYN", ActiveYN),
                                                new OleDbParameter("PRoleID", RoleID)
                                            };
Reply to this message...
 
    
Daniel Naumann
John,

This question has already been answered several times o this list. If you do a
search of the archives you will see a post I did on the 15th July with the
subject "sql server connection". Your answer is in there.

Daniel.

-----Original Message-----
From: Kilgo, John (alt) [mailto:Click here to reveal e-mail address]
Sent: 23-Jul-2002 11:53
To: ngfx-oledb
Subject: [ngfx-oledb] OleDbParameters

I'm working my way through a book on .NET, specifically ADO.Net. There is
an example of updating a table with the data displayed in a datagrid, with
an "Edit" link button. This allows certain columns on any row to be
updated. The example works when connecting to SQL Server using the
SqlClient namespace. I, however, (for reasons I won't go into) must make it
work with OleDb instead. The problem is I receive the error:
System.Data.OleDb.OleDbException: Must declare the variable '@productName'.

A code snippet follows. Any help will be appreciated!

' Update Database
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim sqlString As String

myConnection = New OledbConnection("Provider=blah;blah;blah;)
sqlString = "Update Products Set ProductName = " &
"@productName, UnitPrice = @unitPrice WHERE ProductID=@productID"
myCommand = New OleDbCommand( sqlString, myConnection)
myCommand.Parameters.Add (New OleDbParameter ("@ProductName",
OleDbType.VarChar, 80))
myCommand.Parameters("@ProductName").Value = productName.Text
myCommand.Parameters.Add (New OleDbParameter("@unitPrice",
OleDbType.currency))
myCommand.Parameters("@unitPrice").Value = cType(unitPrice.Text, Decimal)
myCommand.Parameters.Add (New OleDbParameter ("@productID",
OleDbType.Integer))
myCommand.Parameters("@productID").Value =
myDataGrid.DataKeys.Item(e.Item.ItemIndex)
myConnection.Open()
myCommand.ExecuteNonQuery <==== Error occurs here
myConnection.Close()
myDataGrid.EditItemIndex = -1
BindData

Thanks for any help,

John Kilgo
Brandt Information Services, Inc.
Click here to reveal e-mail address
(850) 877-7713 ext. 554

| [ngfx-oledb] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-oledb.asp = JOIN/QUIT

Reply to this message...
 
 
System.Data.OleDb.OleDbCommand
System.Data.OleDb.OleDbConnection
System.Data.OleDb.OleDbException
System.Data.OleDb.OleDbParameter
System.Data.OleDb.OleDbType




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification