Click here to Skip to main content
15,125,074 members
Home / Discussions / Database
   

Database

 
AnswerRe: Dynamic Query Question Pin
smcnulty200014-Jul-11 22:53
Membersmcnulty200014-Jul-11 22:53 
AnswerRe: Dynamic Query Question Pin
dasblinkenlight15-Jul-11 18:00
Memberdasblinkenlight15-Jul-11 18:00 
AnswerRe: Dynamic Query Question Pin
PIEBALDconsult16-Jul-11 5:27
professionalPIEBALDconsult16-Jul-11 5:27 
JokeRe: Dynamic Query Question Pin
Mycroft Holmes16-Jul-11 14:06
professionalMycroft Holmes16-Jul-11 14:06 
GeneralRe: Dynamic Query Question Pin
S Douglas11-Aug-11 10:48
professionalS Douglas11-Aug-11 10:48 
GeneralRe: Dynamic Query Question Pin
PIEBALDconsult11-Aug-11 15:49
professionalPIEBALDconsult11-Aug-11 15:49 
GeneralRe: Dynamic Query Question Pin
S Douglas12-Aug-11 5:48
professionalS Douglas12-Aug-11 5:48 
GeneralRe: Dynamic Query Question Pin
PIEBALDconsult12-Aug-11 18:57
professionalPIEBALDconsult12-Aug-11 18:57 
Here are a couple of simple examples. Not using my usual data access classes.

I prefer the ExecuteScalar, it was designed for this sort of thing.

System.Data.IDbConnection dbc = new System.Data.SqlClient.SqlConnection
(
    @"Server='localhost\SQLEXPRESS'; Database='Rubbish'; Trusted_Connection='True'"
) ;

System.Data.IDbCommand cmd = dbc.CreateCommand() ;

cmd.CommandText = "SELECT @voter_id=Id FROM Account WHERE " + "Name = 'Two'" ;

System.Data.IDbDataParameter prm = cmd.CreateParameter() ;

prm.ParameterName = "@voter_id" ;
prm.DbType = System.Data.DbType.Int32 ;
prm.Direction = System.Data.ParameterDirection.Output ;

cmd.Parameters.Add ( prm ) ;

dbc.Open() ;

cmd.ExecuteNonQuery() ;

int id = (int) prm.Value ;

cmd.Parameters.Clear() ;
cmd.CommandText = "SELECT Id FROM Account WHERE " + "Name = 'Three'" ;

object o = cmd.ExecuteScalar() ;

if ( o != System.DBNull.Value )
{
    id = (int) o ;
}

dbc.Close() ;

GeneralRe: Dynamic Query Question Pin
S Douglas13-Aug-11 9:20
professionalS Douglas13-Aug-11 9:20 
GeneralRe: Dynamic Query Question Pin
PIEBALDconsult13-Aug-11 10:29
professionalPIEBALDconsult13-Aug-11 10:29 
GeneralRe: Dynamic Query Question Pin
S Douglas13-Aug-11 23:30
professionalS Douglas13-Aug-11 23:30 
GeneralRe: Dynamic Query Question Pin
PIEBALDconsult13-Aug-11 8:15
professionalPIEBALDconsult13-Aug-11 8:15 
QuestionUPDATE Multiple tables on one filed. [modified] Pin
Member 808202113-Jul-11 12:12
MemberMember 808202113-Jul-11 12:12 
AnswerRe: UPDATE Multiple tables on one filed. Pin
Blue_Boy14-Jul-11 0:29
MemberBlue_Boy14-Jul-11 0:29 
AnswerRe: UPDATE Multiple tables on one filed. Pin
Shameel14-Jul-11 1:09
professionalShameel14-Jul-11 1:09 
AnswerRe: UPDATE Multiple tables on one filed. Pin
smcnulty200014-Jul-11 23:39
Membersmcnulty200014-Jul-11 23:39 
AnswerRe: UPDATE Multiple tables on one filed. [modified] Pin
Niladri_Biswas18-Jul-11 3:12
MemberNiladri_Biswas18-Jul-11 3:12 
QuestionCalculate and display a progressive balance Pin
Rameez Raja11-Jul-11 21:48
MemberRameez Raja11-Jul-11 21:48 
AnswerRe: Calculate and display a progressive balance Pin
Corporal Agarn12-Jul-11 5:40
professionalCorporal Agarn12-Jul-11 5:40 
AnswerRe: Calculate and display a progressive balance Pin
smcnulty200014-Jul-11 23:34
Membersmcnulty200014-Jul-11 23:34 
GeneralRe: Calculate and display a progressive balance Pin
Rameez Raja16-Jul-11 23:49
MemberRameez Raja16-Jul-11 23:49 
GeneralRe: Calculate and display a progressive balance Pin
smcnulty200018-Jul-11 14:36
Membersmcnulty200018-Jul-11 14:36 
QuestionSelecting multiple columns from several tables without using JOIN Pin
Dominick Marciano11-Jul-11 5:41
professionalDominick Marciano11-Jul-11 5:41 
AnswerRe: Selecting multiple columns from several tables without using JOIN Pin
Blue_Boy11-Jul-11 5:55
MemberBlue_Boy11-Jul-11 5:55 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
David Mujica11-Jul-11 6:28
MemberDavid Mujica11-Jul-11 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.