Thursday, March 22, 2012
dataset query based on a global parameter
records have a userid field filled with many userid values. how can I use the
global paramerer userid in the criteria for my dataset. so when a user run
the report olny records with his or her userid are showncreate a parameter with default value the global parameter. then use that
parameter in the query. ofcourse you can't use caching for those reports
"DJJIII" wrote:
> I need to create a report that displays data based on the userid. all the
> records have a userid field filled with many userid values. how can I use the
> global paramerer userid in the criteria for my dataset. so when a user run
> the report olny records with his or her userid are shown|||You do not have to have a 1:1 mapping between query parameters and report
parameters. Doing it the way suggested here means you have to muck around
with hiding it (since you don't want people to change it).
Have your query parameter, let's call it @.UserID. RS will automatically
recreate a report parameter called UserID but we won't use it. Click on the
..., go to parameters. Map the query parameter @.UserID to the global . The
parameter dialog box has a name and value columns. On the value side switch
it to expression. This brings you to the expression builder where you can
pick the User!UserID global variable. One thing to note, this variable has
the domain as well as the user id, so if you don't want this you will have
to strip it off.
Now, go you your layout, Report->Parameters and delete the now unneeded
UserID report parameter.
--
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Antoon" <Antoon@.discussions.microsoft.com> wrote in message
news:04C477F1-17E5-47C5-BB11-9EF31278F1CE@.microsoft.com...
> create a parameter with default value the global parameter. then use that
> parameter in the query. ofcourse you can't use caching for those reports
> "DJJIII" wrote:
>> I need to create a report that displays data based on the userid. all
>> the
>> records have a userid field filled with many userid values. how can I use
>> the
>> global paramerer userid in the criteria for my dataset. so when a user
>> run
>> the report olny records with his or her userid are shown|||great tip, that is indeed a lot more practical
"Bruce L-C [MVP]" wrote:
> You do not have to have a 1:1 mapping between query parameters and report
> parameters. Doing it the way suggested here means you have to muck around
> with hiding it (since you don't want people to change it).
> Have your query parameter, let's call it @.UserID. RS will automatically
> recreate a report parameter called UserID but we won't use it. Click on the
> ..., go to parameters. Map the query parameter @.UserID to the global . The
> parameter dialog box has a name and value columns. On the value side switch
> it to expression. This brings you to the expression builder where you can
> pick the User!UserID global variable. One thing to note, this variable has
> the domain as well as the user id, so if you don't want this you will have
> to strip it off.
> Now, go you your layout, Report->Parameters and delete the now unneeded
> UserID report parameter.
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Antoon" <Antoon@.discussions.microsoft.com> wrote in message
> news:04C477F1-17E5-47C5-BB11-9EF31278F1CE@.microsoft.com...
> > create a parameter with default value the global parameter. then use that
> > parameter in the query. ofcourse you can't use caching for those reports
> >
> > "DJJIII" wrote:
> >
> >> I need to create a report that displays data based on the userid. all
> >> the
> >> records have a userid field filled with many userid values. how can I use
> >> the
> >> global paramerer userid in the criteria for my dataset. so when a user
> >> run
> >> the report olny records with his or her userid are shown
>
>
Wednesday, March 21, 2012
DataRow syntax
command.CommandText = "SELECT UserName from Users WHERE UserID = " = userID
Executing this command returns one table with one column with one row. What is the syntax for getting that value into a variable? I can get the information into a dataSet but I can't get it out. Should I be using a dataSet for this operation?
The rest of the code so far:
SqlDataAdapter dataAdapter =newSqlDataAdapter();
dataAdapter.SelectCommand = command;
dataAdapter.TableMappings.Add("Table","Users");
dataSet =newDataSet();
dataAdapter.Fill(dataSet);
Using that code, your data would be in dataSet.tables[0].rows[0][0].
If that's always just returning one value, you might want to look into using ExecuteScalar instead of the adapter and dataset.
You can just use executeScalar method of SQl command below is example from VB.Net help for scalar modified a little:
Public Function AddProductCategory( _ ByVal UserID As Integer, ByVal connString As String) As Integer Dim Username As string = "" Dim sql As String = "SELECT UserName from Users WHERE UserID = @.USERID" Using conn As New SqlConnection(connString) Dim cmd As New SqlCommand(sql, conn) cmd.Parameters.Add("@.USERID", SqlDbType.Int) cmd.Parameters("@.USERID").Value = newName Try conn.Open() userName = Convert.ToInt32(cmd.ExecuteScalar()) Catch ex As Exception Console.WriteLine(ex.Message) End Try End Using Return newProdIDEnd FunctionThanks|||
Got it working ... thank you for your help!
Wednesday, March 7, 2012
DataDirection output Problems
I have the below code. When the SqlParameter is created the @.UserID is set as input instead of output. anyone have any ideas why this is happining and how I can get it to work. I can create the variable as a single parameter and set the direction to output and it works but when I try it in the code below it won't work. Any help will be appreciated
Endeavor
Dim parametersAs SqlParameter() = {New SqlParameter("@.strSex", Data.SqlDbType.Char, 50), _New SqlParameter("@.intRace", Data.SqlDbType.Int), _New SqlParameter("@.intAge", Data.SqlDbType.Int), _New SqlParameter("@.UserID", Data.SqlDbType.SmallInt, Data.ParameterDirection.Output)}The overload that takes 3 parameters does not have the direction as the 3rd parameter. If you want to do it that way, you'll need the full overload that takes the 10ish parameters.|||
Thanks for your help. OK I don't need all of the rest of the parameters. Is there any way to make the variable an output and still keep it in the array or add it to the array after creating the sqlparameter.
Endeavor
|||cmd.Parameter("@.Name").ParameterDirection=Output