a simple question  
Author Message
orion41253





PostPosted: Fri Aug 13 21:26:20 CDT 2004 Top

ADO >> a simple question

I have a simple question here,

ConnectToDB();

string queryString = "SELECT Owner,Description FROM Groups WHERE Title =
'BOSS'";

MySqlCommand myCmd = new MySqlCommand(queryString,mycon);

try
{
lblOwner.Text = (string)myCmd.ExecuteScalar();
}
finally
{
myCmd.Dispose();
mycon.Dispose();
}

it's only get one(Owner) value back, so what I need to do so I can pull both
Owner and Description from database?

Thansk in advance.

DotNet278  
 
 
Val





PostPosted: Fri Aug 13 21:26:20 CDT 2004 Top

ADO >> a simple question Hi Jason,

ExecuteScalar method always returns only one value, not multiple values for
one row. You would need to use ExecuteReader to get an access to all the
fields in a row

--
Val Mazur
Microsoft MVP




>
> I have a simple question here,
>
> ConnectToDB();
>
> string queryString = "SELECT Owner,Description FROM Groups WHERE Title =
> 'BOSS'";
>
> MySqlCommand myCmd = new MySqlCommand(queryString,mycon);
>
> try
> {
> lblOwner.Text = (string)myCmd.ExecuteScalar();
> }
> finally
> {
> myCmd.Dispose();
> mycon.Dispose();
> }
>
> it's only get one(Owner) value back, so what I need to do so I can pull
> both
> Owner and Description from database?
>
> Thansk in advance.


 
 
Laiju





PostPosted: Sat Aug 14 00:06:40 CDT 2004 Top

ADO >> a simple question hello...

i think u can achieve the same by using datasets...ie
instead of calling....executescalar...use a dataadapter and user
dataadapter.fill(datasetname)...

ur datatable will have that row with 2 columns ...

hope this will help u.../

smiles,
Laiju


>
> I have a simple question here,
>
> ConnectToDB();
>
> string queryString = "SELECT Owner,Description FROM Groups WHERE Title =
> 'BOSS'";
>
> MySqlCommand myCmd = new MySqlCommand(queryString,mycon);
>
> try
> {
> lblOwner.Text = (string)myCmd.ExecuteScalar();
> }
> finally
> {
> myCmd.Dispose();
> mycon.Dispose();
> }
>
> it's only get one(Owner) value back, so what I need to do so I can pull
both
> Owner and Description from database?
>
> Thansk in advance.


 
 
Cor





PostPosted: Sat Aug 14 04:05:51 CDT 2004 Top

ADO >> a simple question Jason,

As an alternative to the answers from Val and Laiju,
Use two selectsstrings and two executescalars.

I hope this helps?

Cor

> I have a simple question here,
>
> ConnectToDB();
>
> string queryString = "SELECT Owner,Description FROM Groups WHERE Title =
> 'BOSS'";
>
> MySqlCommand myCmd = new MySqlCommand(queryString,mycon);
>
> try
> {
> lblOwner.Text = (string)myCmd.ExecuteScalar();
> }
> finally
> {
> myCmd.Dispose();
> mycon.Dispose();
> }
>
> it's only get one(Owner) value back, so what I need to do so I can pull
both
> Owner and Description from database?
>
> Thansk in advance.