Thursday, May 14, 2009

Code snippet for Return Table

#region ReturnTable
public DataTable $getDBTable$(string $sQuery$)
{
DataTable $retDt$ = null;
string $constring$ =$connectionstring$;
SqlConnection $conn$ = new SqlConnection($constring$);
SqlDataAdapter $sqlDa$ = new SqlDataAdapter();
DataSet $ds$ = new DataSet();
$sqlDa$.SelectCommand = new SqlCommand($sQuery$, $conn$);
$sqlDa$.Fill($ds$);
if ($ds$.Tables.Count > 0)
{
$retDt$ = $ds$.Tables[0];
}

return $retDt$;
}
#endregion

No comments: