?
Solved

arrgh... How to get simple one value to string variable???

Posted on 2003-03-23
6
Medium Priority
?
216 Views
Last Modified: 2010-04-15
I just started to study .NET so my question may be too sily.
How do I get some string value from some table?
In ADO ( old non .NET ) I could open Recordset for example
rs = conn.Execute(someSqlQuery);
and get my data with
sValue = rs.Fields("someField").Value;

How do I do this simple operation in .NET?
0
Comment
Question by:LazyStudent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 23

Expert Comment

by:naveenkohli
ID: 8190205
Here are some samples from documentation.....

SqlCommand myCMD = new SqlCommand("SELECT CategoryID, CategoryName FROM Categories;" +
                                  "SELECT EmployeeID, LastName FROM Employees", nwindConn);
nwindConn.Open();

SqlDataReader myReader = myCMD.ExecuteReader();

do
{
  Console.WriteLine("\t{0}\t{1}", myReader.GetName(0), myReader.GetName(1));

  while (myReader.Read())
    Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));

} while (myReader.NextResult());

myReader.Close();
nwindConn.Close();

**********************

OleDbConnection nwindConn = new OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;" +
                                                "Integrated Security=SSPI;Initial Catalog=northwind");

OleDbCommand selectCMD = new OleDbCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn);
selectCMD.CommandTimeout = 30;

OleDbDataAdapter custDA = new OleDbDataAdapter();
custDA.SelectCommand = selectCMD;

DataSet custDS = new DataSet();
custDA.Fill(custDS, "Customers");
0
 
LVL 5

Author Comment

by:LazyStudent
ID: 8190218
i fear it doesn't answer my question... can you write for me using someSqlQuery, someField values example that performs the same thing I suplied in question?
0
 
LVL 23

Accepted Solution

by:
naveenkohli earned 200 total points
ID: 8190261
If you are using Datareader then...

sValue = myReader["someField"].ToString();

and if you are suing DataSet..

sValue = ds.Tables[0].Rows[0]["someField"].ToString();
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8194637
LazyStudent, just because you are using C# does NOT mean that you cannot also use standard ADO, just like you have used ADO in the past.  ADO.NET is a NEW tool, NOT a replacement for standard ADO.  YOu can add a reference to normal, standard ADO, by clicking on the Solution Expolrer, then Add Reference, then click on the COM tab, ans scroll down to Microsoft ActiveX Data Objects 2.7 (or whatever is the latest version on you PC).  That will add the necessary ADO com-interop wrapper, and ADO will be accessible from your .NET code.

AW
0
 
LVL 5

Author Comment

by:LazyStudent
ID: 8194942
Arthur_Wood: Thank you, I know that.
But my desire ( I hope I am right ) to stay consistent with .NET technologies.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8195600
but there are times to CORRECTLY use ADO , in .NET, and other times to CORRECTLY use ADO.NET.  ADO.NET is NOT intended to be used IN ALL cases, within a >NET based program.

ADO.NET is fundamentally geared to use DISCONNECTED recordsets, and does not function particularly weel if you REALLY need to use a CONNECTED recordset, which is the application area targetted by ADO.  It depends on the nature of the application that you are working on.  DO NOT simply run off to ADO.NET because it is the latest "And greatest".  ADO has been greatly IMPROVED with the release of .NET, but it is still the technology of choice for MANY applications within the .NET arena.

That was my point.

AW

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question