Database Retrieval - Newbie question

  • Thread starter Thread starter Sue
  • Start date Start date
S

Sue

Hello

I'm on the learning curve for c# and .Net. I program in vb.

I'm writing a small application in c# and .net and the database in
Oracle.

I want to open the database and send a query to retreive some values
from the table and store that value in a variable, and if the value is
present then diplay it.

I've opened the databse successfully.
My query is "Select test_notes from tests where test_id = 5", and I
want the value of the field test_notes stored in the variable
strTempNotes.

Could someone help me with the syntax of how I go about doing that. I
know how to do this in VB, but trying to learn to do the same in c#
and .net

thanks
Sue..
 
Sue,

If you know how to do it in VB, then it won't be too different in C# =)

Basically, you have to open a connection to your database first. You
can do this with the OleDbConnection class or the SqlDbConnection (or any
other connection class, depending on your database type). Once you have
that, you can create a command class (SqlCommand, OleDbCommand, etc, etc)
and set the command text to your query, as well as the connection
information.

Finally, since you only want the one value that is returned, you can
call the ExecuteScalar method on the command object to get the value of the
first column in the first row.

Hope this helps.
 
Back
Top