Showing posts with label passing. Show all posts
Showing posts with label passing. Show all posts

Saturday, February 25, 2012

aspx vb sql parameter passing

Hello,
Can someone kindly point out what is wrong with the following code file. I'm trying to:
- fill a dropdown from a db on page load (this works!)
- when user selects from the list and hits a button, pass the dropdown value to a second query
- use the second query to make another call to the db and fill a data grid

In the code below, if I swap an actual value (eg '1005') into the command and comment out the .Parameter.Add statements, the dategrid is filled sucessfully. Otherwise, when the button is pressed, nothing is displayed.

Thanks

PS comments about my coding approach are welcome - I'm new to aspx...


<%@. Language="VBScript" Debug="true"%>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.data.SqlClient" %>
<html>
<head>
<script language="vb" runat="server">
Dim dbConnection As SqlConnection
Dim ds_Teams,ds_Agents As DataSet
Dim sqlCmd_Teams,sqlCmd_Agents As SqlDataAdapter

Dim dbConn = "server=csacd01;uid=mpierce;pwd=cabledog;database=clearviewacd"

Dim sql_select_teams = "" & _
"SELECT team_no, team_name " & _
"FROM dbo.team " & _
"WHERE (team_status = 'Curr')"

Dim sql_select_agents = "" & _
"SELECT last_name + ', ' + first_name AS name, agent_no " & _
"FROM dbo.users " & _
"WHERE (team_no = @.Team) AND (NOT (agent_no = '1029')) " & _
" AND (NOT (last_name IS NULL)) " & _
" AND (NOT (first_name IS NULL)) " & _
" AND (NOT (first_name = 'FirstName')) " & _
"ORDER BY last_name"

Dim teamList = "teamList"
Dim agentList = "agentList"

Sub Page_Load(Sender As Object, E As EventArgs)
if not (IsPostBack)
ds_Teams = new DataSet()
dbConnection = New SqlConnection(dbConn)
sqlCmd_Teams = New SqlDataAdapter(sql_select_teams, dbConnection)
sqlCmd_Teams.Fill(ds_Teams, teamList)
dbConnection.close()

dropdownlist_Teams.DataSource=ds_Teams.Tables(teamList).DefaultView
dropdownlist_Teams.DataBind()
end if
End Sub

sub Get_Agents(Sender As Object, E As EventArgs)
ds_Agents = new DataSet()
dbConnection = New SqlConnection(dbConn)
sqlCmd_Agents = new SqlDataAdapter(sql_select_agents, dbConnection)

sqlCmd_Agents.SelectCommand.Parameters.Add(new SqlParameter("@.Team", SqlDbType.NVarChar,4))
sqlCmd_Agents.SelectCommand.Parameters("@.Team").Value = dropdownlist_Teams.DataValueField

sqlCmd_Agents.Fill(ds_Agents,agentList)

dbConnection.close()

datagrid_Agents.DataSource=ds_Agents.Tables(agentList).DefaultView
datagrid_Agents.DataBind()
end sub

</script>
</head>
<body>
<form runat="server">
<asp:DropDownList id="dropdownlist_Teams" runat="server"
DataTextField="team_name"
DataValueField="team_no">
</asp:DropDownList
<input type="submit" onserverclick="Get_Agents" value="Get Agents" runat="server"><br /
<ASP:DataGrid id="datagrid_Agents" runat="server"
Width="500"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>
</form>
</body>
</html>

(1) dim a variable as string and then assign the sql stmt to the variable.
xample :
dim str1 as string
str1="Select..."

(2) is the valuefield numeric or string type ? also you might want to move the assigning of the str stmt to the get_events event itself rather than declaring it as a global string.

hth

Sunday, February 12, 2012

ASP.NET Authentication for SQL Reporting

Anyone have any good examples on how to have an ASP.NET page login to the ReportingServer to view a report without passing the authentication onto the user?

I've been attempting to use the LogonUser method in the reporting web service but I'm not having any luck. I keep getting "Unauthorized" errors... Doh!

Thanks,my app had its own set of users and my requirement was that once the user logs into the app he shouldnt have to login to report server again to view a report..so I just copied the code from login.aspx in the Pages folder and in a sep aspx page and do both the authentications in the same page and after the authentication redirect to my app instead of folder.aspx...so when the user requests a report he is not prompted for the user name..dont know what you are trying to do is similar to what I did.|||Yea, that's what I'm talking about. However, the reports are protected via IIS, so I've been trying to use the LogonUser method of the ReportingService webservice but I haven't had any luck.|||

Can you share your code?

The code to log in the web service in vb is below

rs.Credentials =New NetworkCredential("user name", "password", "domain")

Additional info can be found athttp://devx.icpconline.com/Default.aspx?PageContentID=19&tabid=147