Simple DataAdapter doesnt work

My original code was working. Then my coworker made a change to the DAL and I have to use DBDataAdapter. I don't get an error with this piece of code BUT the dataset is not filled..skips the
dbAdapter.Fill(ds); line and goes to "finally" section. Not sure what's wrong.

My ****Orginal**** code was like this:
SqlDataAdapter myAdapter = new SqlDataAdapter();
           cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "pSearchLastName";

                cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = cName;

                    myAdapter.SelectCommand = cmd;

****new code that doesnt work
using (DbConnection cn = this.Database.CreateConnection())
               using (DbCommand cmd = this.Database.GetStoredProcCommand("pSearchLastName"))
                   DbDataAdapter dbAdapter = null;
                     this.Database.AddInParameter(cmd, "@name", DbType.String, cName);
                       cmd.Connection = cn;
                       dbAdapter.SelectCommand = cmd;
                       dbAdapter.Fill(ds); //** doesnt even get to here
                       foreach (DataRow row in ds.Tables[0].Rows)

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
do you have an catch (Exception ex) for your "try" ? you should have, and get the error described there.
CamilliaAuthor Commented:
let me look at it again. It doesnt go thru the exception but let me see again..
CamilliaAuthor Commented:
yes, i didnt have the right exception trap.I get:
Object reference not set to an instance of an object

but what's wrong with dbAdapter.SelectCommand = cmd; ??
howcome my orig code works and the new one doesnt? is it because i have:
DbDataAdapter dbAdapter = null; ??

Been at this for 4 hours now!
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

CamilliaAuthor Commented:
Do I need to create the DBAdapter??
// Create the DbDataAdapter.
            DbDataAdapter adapter = factory.CreateDataAdapter();
            adapter.SelectCommand = command;

I dont have CreateDataAdapter...
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>Do I need to create the DBAdapter??

yes, you indeed need to do that.
what is "this.Database" as object?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CamilliaAuthor Commented:
In my original code i have:
SqlDataAdapter myAdapter = new SqlDataAdapter();

but cant do that with DbDataAdapter: DbDataAdapter dbAdapter = new DbDataAdapter();
gives me an error...

>> what is "this.Database" as object?
I see this with this.Database ...trying it now...
DbDataAdapter dbAdapter = this.Database.GetDataAdapter();
CamilliaAuthor Commented:
Once again, thanks for helping me out. That "this.Database.GetDataAdapter()" worked.

You're a life saver :) Kamila.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.