Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am new to ADO.net. I have learned programming in Connected mode. Now i am learning ADO.net 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

SQL
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 ADO.net 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

1 solution

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.
 
Share this answer
 
Comments
Member 9427602 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 ADO.net 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900