Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL ADO.NET
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
 
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 31-Dec-12 6:50am

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
Member 9427602 at 31-Dec-12 13:19pm
   
for some security reason i cannot use connection. Can you please provide me the solution in disconnect mode?
PIEBALDconsult at 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)

  Print Answers RSS
0 OriginalGriff 253
1 Maciej Los 205
2 Nguyen.H.H.Dang 190
3 Peter Leow 185
4 arvind mepani 162


Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid