Solved

Problems building sql statement using oledbparameter

Posted on 2004-08-02
3
410 Views
Last Modified: 2008-02-01
Using sql db I get the following compile error.

BC30002: Type 'OleDbParameter' is not defined.

I am new at asp so bear with me. I got the following code off of 4guysfromrolla website.
Maybe there is a better way to build the sql statement. I am trying to get the update portion of my datagrid to update after an edit.

Sub CustomerData_Update(sender As Object, e As DataGridCommandEventArgs)
   Dim oDR as System.Data.SQLClient.SQLDataReader
   Dim oCom As System.Data.SQLClient.SqlCommand
   Dim oConn as System.Data.SQLClient.SQLConnection
      
   'Read in the values of the updated row
   Dim indi as String = e.Item.Cells(1).Text
   Dim lname as string = CType(e.Item.Cells(2).Controls(0), TextBox).Text
   Dim mi as string = CType(e.Item.Cells(3).Controls(0), TextBox).Text
   Dim fname as String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
   Dim address1 as String = CType(e.Item.Cells(5).Controls(0), TextBox).Text
   'Construct the SQL statement using Parameters
    Dim strSQL as String = _
      "UPDATE [distributor] SET [lname] = @lname, " & _
      "[UnitPrice] = @UnitPrice, [ProductDescription] = @ProdDesc " & _
      "WHERE [ProductID] = @ProductID"

    oConn = New System.Data.SQLClient.SQLConnection ("server=mssql01.1and1.com; initial catalog=db106189075;uid=dbo106189075;pwd=aZf65Snc")
      oConn.Open()
                  
    'Dim myCommand as OleDbCommand = new OleDbCommand(strSQL, objConn)
      oCom=new System.Data.SQLClient.SQLCommand()
    oCom.CommandType = CommandType.Text

    ' Add Parameters to the SQL query

** the error comes from the below line.
    Dim parameterProdName as OleDbParameter = new OleDbParameter("@lname", OleDbType.text, 75)
    parameterProdName.Value = strName
    oCom.Parameters.Add(parameterProdName)


    oCom.ExecuteNonQuery()   'Execute the UPDATE query
   
    oCom.Close()   'Close the connection
  'Finally, set the EditItemIndex to -1 and rebind the DataGrid
    oCom.EditItemIndex = -1
    Page_Data()        
End Sub
0
Comment
Question by:Jimbo456
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 500 total points
ID: 11700552
Hi there,
you are using "System.Data.SQLClient"... and the parameter you are creating is  OleDbParameter. That's why you are having problems. It should be...
Dim parameterProdName As New SqlParameter("@lname", SqlDbType.VarChar)

Try these links:
http://www.developerfusion.com/show/4278/3/
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlParameterClassTopic.asp

-Baan
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11700591
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11703407
tell me those aren't your actual SQL server account settings.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question