Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Problem using a Parameterized Command as the Select Command for a Data Adapter

Problem using a Parameterized Command as the Select Command for a Data Adapter

Scheduled Pinned Locked Moved Database
databasehelpcsharpsql-serverdotnet
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paulo
    wrote on last edited by
    #1

    Seems that using a parameterized query as a SelectCommand for an OleDbDDataAdapter to fill a DataSet doesn't work! The following code is how I'm doing that. All the code is inside an try/catch block. The language i'm using is C# // Using a UDL file for the connection string string strDBConn = "FileName=D:\Contacts.udl;"; // Sets up the connection OleDbConnection conn = new OleDbConnection(strDBConn); conn.Open(strDBConn); // Creates a new command OleDbCommand cmd = new OleDbCommand( "select * from dbo.Contacts where contact_id = ?", conn); // Sets up the Data Adapter OleDbDataAdapter da = new OleDbDataAdapter(); da.SelectCommand = cmd; // Sets the Command parameters param = da.SelectCommand.Parameters.Add ( "@contact_id", OleDbType.Numeric, 9, "entid_id"); param.Value = 1; // The parameter value // creates a new DataSet DataSet dsResult = new DataSet() // Fills the DataSet da.Fill(dsResult); Somehow in the last instruction it generates an exception that even 'catch (Exception e)' can't get exactly because in spite of falling in this catch block the 'e' (the exception) is null! But the reason he is throwing some weird exception is because the parameters are not being declared first before querying the database with the parameterized select command and consequently the string that is being sent is only "select * from dbo.Contacts where contact_id = @P1" and nothing else. I'm using a .UDL file to set my connection string which is set with valid parameters because it's being used everywhere else in the app and it works perfectly. My Database is SQL Server 2000... Yeah, of course I could use SqlDataAdapter and all the other classes specific for SQL Server but the fact is that I want to use an .UDL file to set my datasource and the only way to do this is using the OleDb... classes. UDL files doesn't work with SqlConnection in case you didn't know. So... am I doing something wrong here in setting the Data Adapter to a parameterized query? Is this a bug in the .NET framework? Can you help me out with this? Thanks in advance :) Best Regards, Paulo

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups