Help With DataSets
-
Hello [WebMethod Description="Returns true if User ID in Database")] public bool isUserIdValid( int nUserID ) { DataSet myData = new DataSet(); sqlDataAdapter1.SelectCommand.Parameters["@userID"].Value = nUserID; sqlDataAdapter1.Fill( myData, "UserID"); myData.Tables[???? return true; } Lets say we have a web method such as the one above, it calls a stored procedure on an sql database and returns an int, 0 if user id invalid, or the value of the user id if valid. So, Ive passed the @userid to the sqlDataAdapter and filled a dataset ie myData with the results. How do I now get at the data in the DataSet myData ive just created????? Please help with code required to get the value returned by the stored procedure Regards Li Mu Bai Wudan Master (Deceased)
-
Hello [WebMethod Description="Returns true if User ID in Database")] public bool isUserIdValid( int nUserID ) { DataSet myData = new DataSet(); sqlDataAdapter1.SelectCommand.Parameters["@userID"].Value = nUserID; sqlDataAdapter1.Fill( myData, "UserID"); myData.Tables[???? return true; } Lets say we have a web method such as the one above, it calls a stored procedure on an sql database and returns an int, 0 if user id invalid, or the value of the user id if valid. So, Ive passed the @userid to the sqlDataAdapter and filled a dataset ie myData with the results. How do I now get at the data in the DataSet myData ive just created????? Please help with code required to get the value returned by the stored procedure Regards Li Mu Bai Wudan Master (Deceased)
Li Mu Bai wrote: How do I now get at the data in the DataSet myData ive just created????? Have you tried to access the data like so:
myData.Tables["UserID"]
So your code could possibly look something like:[WebMethod Description="Returns true if User ID in Database")]
public bool isUserIdValid( int nUserID )
{
DataSet myData = new DataSet();sqlDataAdapter1.SelectCommand.Parameters["@userID"].Value = nUserID;
// Check to make sure the stored proc returned rows,
// otherwise accessing the ds could throw an exception.
//
if ( sqlDataAdapter1.Fill( myData, "UserID") > 0 )
{
// Validate the returned ID. If the value is not 0
// then the user is valid.
//
if ( myData.Tables["UserID"] != 0 )
{
return true;
}
}return false;
}Roger Stewart "I Owe, I Owe, it's off to work I go..."