System.Data.OleDb.OleDbException on DataSource/DataList - asp.net

I'm relatively new, so it shouldn't be too surprising I haven't seen the error before, but when I try to run a page, I get the error System.Data.OleDb.OleDbException: IErrorInfo.GetDescription failed with E_FAIL(0x80004005)
Here is the code for that page:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT * FROM [Docs] WHERE Section = 1">
</asp:AccessDataSource>
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT * FROM [Docs] WHERE Section = 2">
</asp:AccessDataSource>
<asp:AccessDataSource ID="AccessDataSource3" runat="server"
DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT * FROM [Docs] WHERE Section = 3">
</asp:AccessDataSource>
<asp:AccessDataSource ID="AccessDataSource4" runat="server"
DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT * FROM [Docs] WHERE Section = 4">
</asp:AccessDataSource>
<h2>Benefits Information</h2>
<br />
<asp:Label ID="OpenEnrollmentHeader" runat="server" Text="Open Enrollment" CssClass="BenefitsHeaderStyle" />
<asp:DataList ID="DataList1" runat="server" CellPadding="10"
DataSourceID="AccessDataSource1">
<ItemTemplate>
<asp:HyperLink ID="OpenEnrollmentDocs" runat="server" Text='<%# Eval("Label") %>'
NavigateUrl='<%# "~/docs/HRDocs/" & Eval("Filename") %>' />
</ItemTemplate>
</asp:DataList>
<br />
I can see that it must have something to do with my data sources or the Datalist control, but I have no idea what. Any ideas? I can tell you that there is one result in the first select statement and none, perhaps, in the others.

Your code contains a reserved word, ill try and pick it out now

Related

Dropdown list change based on other dropdown list in details view ASP.NET

I have two dropdown lists in a detailsview one called College and the other is Department. If the user select a college, the department dropdown list should generate all the departments for the selected college.
Here is the detailsview and the dropdown lists:
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="600px" AutoGenerateRows="False" CssClass="table table-bordered mtop" DataKeyNames="ID" DataSourceID="SqlDataSource1" OnDataBound="DetailsView1_DataBound">
<FieldHeaderStyle CssClass="DetailsViewHeader" Width="200px" />
<Fields>
<asp:TemplateField HeaderText="College" SortExpression="Colleges">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource3" DataTextField="ArName" DataValueField="Code"></asp:DropDownList>
<asp:HiddenField ID="HiddenColl" runat="server" value='<%# Eval("Colleges") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label15" runat="server" Text='<%# Bind("Colleges") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Department" SortExpression="ArName">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="ArName" DataValueField="Code"></asp:DropDownList>
<asp:HiddenField ID="HiddenDep" runat="server" value='<%# Eval("ArName") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("ArName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:Button ID="Button2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
<asp:Button ID="btnDelete" runat="server" CausesValidation="False" Text="Delete" OnClientClick="return confirm('Do you want to delete ?');" OnClick="btnDelete_Click" />
</ItemTemplate>
<ControlStyle CssClass="btn-login" />
<ItemStyle CssClass="text-center" />
</asp:TemplateField>
</Fields>
</asp:DetailsView>
Here is the SqlDataSources:
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:UEDConnectionStringMarwaMarwa %>" SelectCommand="SELECT [ArName], [Code] FROM [College]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:UEDConnectionStringMarwaMarwa %>" SelectCommand="SELECT [Code], [ArName] FROM [Department] WHERE ([CollegeCode] = #CollegeCode)">
<SelectParameters>
<asp:ControlParameter ControlID="DetailsView1$DropDownList2" Name="CollegeCode" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
This is the error message:
Could not find control 'DetailsView1$DropDownList2' in
ControlParameter 'CollegeCode'
I did this DetailsView1$DropDownList2 so it can access the dropdown list that is inside the detailsview
What is the problem ?
I am unfamiliar with the DetailsView and not experienced with the SqlDataSource, but I will try to help.
In my experience, I have learned that you shouldn't try to assume a control's ClientID. So, first I would recommend getting the ClientID from the server control.
Using an inline expression, I would try something like this:
<asp:ControlParameter ControlID='<%= DetailsView1.Rows(0).FindControl("DropDownList2").ClientID %>' Name="CollegeCode" PropertyName="SelectedValue" Type="Int32" />
For more about asp.net inline expressions see Introduction to ASP.NET inline expressions in the .NET Framework.
Because I am unfamiliar with the DetailsView control, I don't know if there will be a row at index 0 in the DetailsView when it executes this inline expression (which would throw an exception).
If that code doesn't work, I would suggest dynamically setting the ControlID on the back end that executes after the DetailsView1 rows are bound (such as inside the DetailsView1's DataBound event method).
VB:
If DetailsView1.Rows.Count > 0 Then
Dim objDropDownList2 as Control = DetailsView1.Rows(0).FindControl("DropDownList2")
If objDropDownList2 IsNot Nothing Then
SqlDataSource1.SelectParameters("CollegeCode").ControlID = objDropDownList2.ClientID
End If
End If
C#:
if (DetailsView1.Rows.Count > 0) {
Control objDropDownList2 = DetailsView1.Rows(0).FindControl("DropDownList2");
if (objDropDownList2 != null) {
SqlDataSource1.SelectParameters("CollegeCode").ControlID = objDropDownList2.ClientID;
}
}
I hope this helps!

Accessing Controls from another formview inside the same page

I have several forms, each with their own DDL, that I'm using inside a page. I have them in different forms because I need different data sources for each DDL. When I press the Submit button, it gives me an error that it can't find the control "ddlCategory". I assume it is because it is in a different form. Here is the markup:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource1" DefaultMode="Insert" >
<InsertItemTemplate>
Select a Category:<br />
<asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True"
DataSourceID="AccessDataSource1" DataTextField="ORG_NAME"
DataValueField="ID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:FormView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT * FROM [ORGANIZATIONS]"/>
<br />
<asp:FormView ID="FormView2" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource2" DefaultMode="Insert" >
<InsertItemTemplate>
Select an Organization:<br />
<asp:DropDownList ID="ddlOrg" runat="server"
DataSourceID="AccessDataSource2" DataTextField="SectionName"
DataValueField="ID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:FormView>
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ID,SectionName FROM ORG_SECTIONS WHERE OrgID=#OrgID ">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCategory"
PropertyName="SelectedValue"
Name="ID" Type="String"
DefaultValue="" />
</SelectParameters>
</asp:AccessDataSource>
<br />
<asp:FormView ID="FormView3" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource3" DefaultMode="Insert" >
<InsertItemTemplate>
Select an Attorney:<br />
<asp:DropDownList ID="ddlAtty" runat="server"
DataSourceID="AccessDataSource3" DataTextField="Expr1" DataValueField="ATTY_ID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:FormView>
<asp:AccessDataSource ID="AccessDataSource3" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ATTY_ID, NAME & ' ' & INITIAL & ' ' & LASTNAME AS Expr1 FROM ATTORNEYS ORDER BY NAME & INITIAL & ' ' & LASTNAME">
</asp:AccessDataSource>
Also, if there is a way to do it inside one formview control, I'd like to know that too.
Did it this way:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT * FROM [ORGANIZATIONS]"/>
<asp:AccessDataSource ID="AccessDataSource3" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ATTY_ID, NAME & ' ' & INITIAL & ' ' & LASTNAME AS Expr1 FROM ATTORNEYS ORDER BY NAME & INITIAL & ' ' & LASTNAME">
</asp:AccessDataSource>
<br />
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource1" DefaultMode="Insert" >
<InsertItemTemplate>
Select a Category:<br />
<asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True"
DataSourceID="AccessDataSource1" DataTextField="ORG_NAME"
DataValueField="ID">
</asp:DropDownList>
<br />
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ID,SectionName FROM ORG_SECTIONS WHERE OrgID=#OrgID ">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCategory"
PropertyName="SelectedValue"
Name="ID" Type="String"
DefaultValue="" />
</SelectParameters>
</asp:AccessDataSource>
Select an Organization:<br />
<asp:DropDownList ID="ddlOrg" runat="server"
DataSourceID="AccessDataSource2" DataTextField="SectionName"
DataValueField="ID">
</asp:DropDownList>
<br />
Select an Attorney:<br />
<asp:DropDownList ID="ddlAtty" runat="server"
DataSourceID="AccessDataSource3" DataTextField="Expr1" DataValueField="ATTY_ID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:FormView>
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="AddRec" />
And the code behind:
protected void AddRec(object sender, EventArgs e)
{
DropDownList ddlCategory = (DropDownList)FormView1.FindControl("ddlCategory");
DropDownList ddlOrg = (DropDownList)FormView1.FindControl("ddlOrg");
DropDownList ddlAtty = (DropDownList)FormView1.FindControl("ddlAtty");
string constr = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\webvideos.mdb;";
string cmdstr = "INSERT INTO [Org_Sec_Atty] ([OrgID], [SecID], [Atty_ID]) VALUES (?, ?, ?)";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand com = new OleDbCommand(cmdstr, con);
con.Open();
com.Parameters.AddWithValue("#OrgID", ddlCategory.SelectedValue);
com.Parameters.AddWithValue("#SecID", ddlOrg.SelectedValue);
com.Parameters.AddWithValue("#AttyID", ddlAtty.SelectedValue);
com.ExecuteNonQuery();
con.Close();
Response.Redirect("ManageProfAffs.aspx");
}
And done.

How to load a video using a string from a database?

I've got a website where I want to be able to generate a list of videos available on my server. Once that user selects a video, it would take them to another page where it plays the video. So far, I've got no errors on either of the pages, but nothing is showing up either :(
Here's the code for my pages:
word.aspx
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT TOP 5 * FROM [Videos] WHERE ID=#ID AND Program LIKE 'Word'">
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID" />
</SelectParameters>
</asp:AccessDataSource>
<asp:DataList ID="DataList1" runat="server" DataSourceID="AccessDataSource1" RepeatColumns="5">
<ItemTemplate>
<table>
<tr>
<td>
<asp:HyperLink ID="VidLink1" runat="server" Target="_blank" NavigateUrl='<%# "VideoPlayer.aspx?ID=" & Eval("ID") %>' >
<asp:Image ID="VidThumb" runat="server" ImageUrl='<%# "videos/TraningVideos/Thumbnails" & Eval("Thumbnail") %>' /></asp:HyperLink>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
And here's VideoPlayer.aspx:
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT * FROM Video WHERE ID=#ID" >
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID" />
</SelectParameters>
</asp:AccessDataSource>
'
width="450" height="380">
' />
<param name="autostart" value="false" />
<param name="controller" value="true" />
</object>
<ASPNetFlashVideo:FlashVideo ID="FlashVideo1" runat="server" VideoURL="http://www.youtube.com/watch?v=okHuuMbIg1E">
</ASPNetFlashVideo:FlashVideo>
<ASPNetFlashVideo:FlashVideo ID="FlashVideo2" runat="server" VideoURL='<%# "~/videos/TrainingVideos/" & Eval("Filename") %>'>
</ASPNetFlashVideo:FlashVideo>
As you can see, I've even tried using a regular youtube link for the ASPNetFlashVideo control that I've been able to add, and it hasn't been working either. Any ideas?

Select query run in `Visual Studio` but not in browser

I have a datalist control which is connected to a SQLDataSource when i test the data source query with the query builder it returns the data set however when i then run the website in any browser the query does not return a data set.
It seems like the website is not recompiling properly however i am not getting any build errors.
Does anyone have any idea for a possible solution.
Thanks in advance
my sqldatasource code is-
<asp:SqlDataSource ID="SqlDataSourceSearch" runat="server" ConnectionString="<%$ ConnectionStrings:BazaarCeramicsConnectionString %>"
SelectCommand="SELECT Categories.Name, Products.ProductID, Products.Name AS Expr1 FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID WHERE (Products.Name LIKE '%' + #SearchQuery + '%')">
<SelectParameters>
<asp:QueryStringParameter Name="SearchQuery" QueryStringField="search"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
my datalist code is-
<asp:DataList ID="DataList1" runat="server" DataKeyField="ProductID" DataSourceID="SqlDataSourceSearch">
<ItemTemplate>
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
<br />
ProductID:
<asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />
<br />
Expr1:
<asp:Label ID="Expr1Label" runat="server" Text='<%# Eval("Expr1") %>' />
<br />
Here is my input-
<div class="searchBox">
<asp:TextBox ID="SearchTextBox" runat="server"></asp:TextBox>
<asp:Button ID="SearchButton" runat="server" onclick="Button1_Click" Text="Search" />
<img id="cartIcon" src="Images/shoppingCartIcon.png" />
</div>
Here is the code behind
protected void Button1_Click(object sender, EventArgs e)
{
string SearchTerm = SearchTextBox.Text;
Response.Redirect("SearchResults.aspx?SearchQuery=" + Server.UrlEncode(SearchTerm));
}
here is my connection string-
<add name="BazaarCeramicsConnectionString" connectionString="Data Source=CATHERINE\SQLEXPRESS;Initial Catalog=BazaarCeramics;User ID=****;Password=******"
providerName="System.Data.SqlClient" />
(Products.Name LIKE '%' + #SearchQuery + '%')

SqlDataSource-Query in a repeater to use repeater-elements

I would like to do the following with asp.net and C#:
An SqlDataSource fetches a list of templates from the database. Then, in a repeater, for each template a DropDownList-element is created, that contains the found types for each template. Is this possible?
<asp:SqlDataSource ID="src_template" runat="server" ConnectionString="<%$ ConnectionStrings:VConStr %>" SelectCommand="SELECT [template] FROM [template]" />
<asp:Repeater ID="rpt_template" runat="server" DataSourceID="src_template" OnItemCommand="rpt_template_ItemCommand">
<ItemTemplate>
<p>
<asp:SqlDataSource ID="src_types" runat="server" ConnectionString="<%$ ConnectionStrings:VConStr %>" SelectCommand='SELECT [type] FROM [templatetype] WHERE [template] = <%# Eval("template") %>' />
<label for="DropDownList1"><%# Eval("template") %></label>
<asp:DropDownList ID="DropDownList1" runat="server" DatasourceID="src_types" DataTextField="type" DataValueField="type" />
</p>
</ItemTemplate>
</asp:Repeater>
How do I fill the where-part correctly?
Try something like this:
<ItemTemplate>
<asp:HiddenField ID="template" runat="server"
Value='<%# Eval("template") %>'
/>
<asp:SqlDataSource ID="src_types" runat="server"
ConnectionString="<%$ ConnectionStrings:VConStr %>"
SelectCommand="SELECT [type] FROM [templatetype] WHERE [template] = #template"
>
<SelectParameters>
<asp:ControlParameter
Name="template"
Type="String"
ControlID="template"
PropertyName="Value"
/>
</SelectParameters>
</asp:SqlDataSource>
...
</ItemTemplate>

Resources