Hello,
I have a C# Datalist whose records are bound to an external database. When I press a button, I want the program to see whether the value I entered in the textbox actually exists in my Datalist. Can this be done? And if so, how?
The purpose of entering the name into the textbox is to act as another security measure. If eg. I see "Jennie Greene" in the list and I want a list of her books, I must enter her name in the textbox where the program must check if there really is a "Jennie Greene" in the Datalist. If her name is misspelled or the name doesn't appear in the list, a message must appear and tell me that an error occured. However, if the name that is entered in the textbox corresponds with that in the list, I must be redirected to another page.
Below I’ve added my coding
The aspx coding looks like this:
<asp:TextBox ID="txtitemtofind" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btnfind" runat="server" Text="Find" onclick="btnfind_Click" />
<br />
<asp:Label ID="lblfinder" runat="server" Text=""></asp:Label>
<br />
<asp:DataList ID="dlnames" runat="server">
<ItemTemplate>
<asp:Label ID="lblauthornames" runat="server" Text='<%#Eval("[Skrywer name]") %>'></asp:Label>
</ItemTemplate>
</asp:DataList>
Below is my code-behind to tell the program to connect to the database:
string connStr = WebConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString;
OleDbConnection ConnectionString2 = new OleDbConnection(connStr);
ConnectionString2.Open();
string asking = String.Format(("SELECT * FROM [skrywer name] WHERE([Skrywer name] LIKE 'A%')"));
OleDbCommand com = new OleDbCommand(asking, ConnectionString2);
try
{
OleDbDataReader reader = com.ExecuteReader();
dlnames.DataSource = reader;
dlnames.DataBind();
reader.Close();
}
catch
{
lblfinder.Text=”Error”;
}
finally
{
ConnectionString2.Close();
}
And here is my web.config’s connectionstring settings
<connectionStrings>
<add name="ConnectionString2" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Abc\ebooks converts\Skrywers, boeke en reekse.accdb'" providerName="System.Data.OleDb"/>
</connectionStrings>
Can someone please help me?
Riddleride