Hi,
I have a small application that reads an access database. I'm able to load the data, but it's in ascii. I created a function that does the conversion but for some reason I can't figure out how to implement it correctly. Where do I call the AsciiToString() function? Here is my code, thanks so much.
aspx
<asp:DropDownList ID="mydropdownList" runat="server" />
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadSearchList();
}
}
private void LoadSearchList()
{
//Declare objects
OleDbConnection conn;
OleDbCommand comm;
OleDbDataReader reader;
//Read the connection string from Web.config
string connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
// Initialize connection
conn = new OleDbConnection(connectionString);
// Create command
comm = new OleDbCommand("SELECT myID, title FROM books", conn);
//Enclose database code in Try-Catch-Finally
try
{
//Open the connection
conn.Open();
//Execute the command
reader = comm.ExecuteReader();
while (reader.Read())
{
//Populate the list of categories
mydropdownList.DataSource = reader;
mydropdownList.DataValueField = "myID";
mydropdownList.DataTextField = "title";
mydropdownList.DataBind();
}
//close the reader
reader.Close();
}
catch
{
}
finally
{
//Close the connection
conn.Close();
}
}
private static string AsciiToString(string content)
{
StringBuilder sbTemp = new StringBuilder(content.Length);
string StrValue = "";
while (content.Length > 0)
{
StrValue += System.Convert.ToChar(System.Convert.ToInt32(content.Substring(0, 3))).ToString();
content = content.Substring(3, content.Length - 3);
}
content = StrValue;
return content;
}