Click here to Skip to main content
13,597,485 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am new to I have learned programming in Connected mode. Now i am learning disconnected mode. I am facing a problem now:- I have a datatable name "Info". It has four fields :- "ID","Name","Address". Now i want that when user write a ID number and click on button then other two textboxes will show corresponding Name and address. I think SQL statement should be like

SqlCommand cmd = new SqlCommand();
    Cmd.CommandText = "Select Name, Address from Info where ID = @id";
    cmd.Parameters.AddWithValue("id", TextBox1.Text);

I am writing above code using my connected mode Experience. We used a Datareader in Connected mode. But we cannot use DATAREADER in Disconnected mode so how can it be done. Please help me..

Also told me a good link where i can learn INSERT, UPDATE and Delete operation using (i)SQLDataAdapter (ii) SqlCommandBuilder

I have googled alot for good tutorial but everyone has own style of coding and logic therefore i am really confused...
Posted 31-Dec-12 6:50am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

That looks OK to me (I'm olde school). Aren't you expecting only one record back? So read it with a DataReader and disconnect. What's the problem?

However, I wonder why the user would need to enter an ID -- in my opinion users should never know any IDs.
31-Dec-12 13:19pm
for some security reason i cannot use connection. Can you please provide me the solution in disconnect mode?
PIEBALDconsult 31-Dec-12 13:52pm
Everything in goes through a Connection, a Command, and a DataReader no matter what higher level abstractions you use -- I prefer to eliminate the middlemen. What I expect you mean by "disconnect mode" is merely that you don't leave the Connection open for the duration of the appliacation, but rather open it when you need it then close it again, which is what a DataAdapter does behind the scenes (unless you tell it otherwise). It's also what I do with my own data access classes. Instantiate, open/close, open/close, open/close, ..., Dispose. That's what "disconnected" means to me, and I believe what I was taught ten years ago.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180621.3 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100