TheWizardofInt Posted October 1, 2002 Posted October 1, 2002 Does anyone have an example of accessing a SQL database using ADO.Net? I just need a kick start on this. Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
*Gurus* Derek Stone Posted October 1, 2002 *Gurus* Posted October 1, 2002 Dim oConnection As New SqlConnection Dim oCommand As New SqlCommand Dim oDataReader As SqlDataReader oConnection.ConnectionString = "user id=;password=;database=;server=;Connect Timeout=15" oConnection.Open() oCommand.Connection = oConnection oCommand.CommandText = "SELECT * FROM myTable" oDataReader = oCommand.ExecuteReader() While oDataReader.Read() 'Loop though data End While oDataReader.Close() oConnection.Close() Quote Posting Guidelines
Guest kdn102 Posted October 31, 2002 Posted October 31, 2002 Does anyone have the same example for C++? Quote
Vitaly Posted November 15, 2002 Posted November 15, 2002 Derek, and if you use sqlDataReader, what is the equivalent for ADO 2.6 EOF, BOF or Field collection? Thanks. Quote
*Gurus* Derek Stone Posted November 15, 2002 *Gurus* Posted November 15, 2002 EOF: SqlDataReader.Read = False BOF: No equivalent and no need for one. It's the beginning if you haven't called .Read yet. Field collection: Item Collection Quote Posting Guidelines
Guest hesaigo999ca Posted November 16, 2002 Posted November 16, 2002 Is ther any property that allows me to know if a connection object is closed (i.e. VB6 = if recordset.state = adstateopen then Quote
Administrators PlausiblyDamp Posted November 17, 2002 Administrators Posted November 17, 2002 the SQLConnection object has a state property. dim conn as System.Data.SqlClient.SQLConnection if conn.State = ConnectionState.Closed 'Connection closed end if Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
sjchin Posted March 28, 2003 Posted March 28, 2003 Can we open new reader while i doing loop of 1 reader? example : oDataReader = oCommand.ExecuteReader() While oDataReader.Read() 'Loop though data ' At there contain read to other sql statement to retrieve info End While Quote
*Gurus* Derek Stone Posted March 28, 2003 *Gurus* Posted March 28, 2003 Yes, but you'll need a second connection. Only one DataReader can be associated with a connection at a time. Quote Posting Guidelines
hemenkap Posted March 29, 2003 Posted March 29, 2003 hi possiblydamp, just a little bit confused as to checking the connection state using the code dim conn as System.Data.SqlClient.SQLConnection if conn.State = ConnectionState.Closed 'Connection closed end if -------------------------------------------------------------------------------- as you stated above. i think this will check the connection state. how exactly can i do it for a datset? like we do for recordset. is there any method. also while searching in recordset using find command we can know the cursor position in the recordset. in dataset.table.Select we can search the fields but can we get the location where the search stopped ? help. Quote
*Gurus* Derek Stone Posted March 29, 2003 *Gurus* Posted March 29, 2003 A DataSet doesn't have a connection state. It is always disconnected, as that is its nature. Quote Posting Guidelines
Roey Posted April 1, 2003 Posted April 1, 2003 Hi Guys, I'm just doing a bit of research towards moving across to VB.Net and was wondering why you would use this method as opposed to using a SqlDataAdapter, which would utilize a disconnected SqlConnection. What are the advantages / disadvantages of each method. Thanks Quote
*Experts* jfackler Posted April 1, 2003 *Experts* Posted April 1, 2003 A datareader is a forward only read of data...very fast but only reads doesnt allow for dataset manipulation. "Adapters are used to exchange data between a data source and a dataset. In many applications, this means reading data from a database into a dataset, and then writing changed data from the dataset back to the database. However, a data adapter can move data between any source and a dataset. For example, there could be an adapter that moves data between a Microsoft Exchange server and a dataset." (From the search of "Visual Basic and Visual C# Concepts") Quote
Roey Posted April 1, 2003 Posted April 1, 2003 Thanks for your help on tha above questions it was really informative. Just one more question. In n-tier applications that I previously developed, I often used recordsets to pass data back and forth across different tiers. How does this work in regards to DataAdapters and DataReaders. Quote
*Experts* jfackler Posted April 2, 2003 *Experts* Posted April 2, 2003 Depends on how your going to implement the app. If you're serving up data across a large network, the best way is asp.net. Uses the same disconnected dataset and all the work is done on the server. No worries about cursors, the adapter takes care of that for you. That what you're concerned about? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.