Skip to main content

Posts

Showing posts with the label c#

Automatic class or object maker for Access tables in C#

The entity framework is all very well when you run SQL. But what about all of us that are running Access, or are porting old access systems to the web and need to keep legacy systems in place? I was keen to us the object data source to work with data and could not find anything that was able make a class for me. So I wrote my own that listed the tables in the database, then created the class file and stored it in the temp directory. I have a separate code folder to dump these in so that the project does not play with them, rather than dumping them into the App_Code  folder, but you can change this. I placed this code in the test folder of my app which is called  TrackerDotNet So here is the code: First the HTML file <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AutoClassMaker.aspx.cs" Inherits="TrackerDotNet.test.AutoClassMaker" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht...

String index array to calculate totals using Dictionary type

Thought I would document this, since it took me a while to gather all the information to do it, but once I got it, it was very useful. I searched things like how to create a string indexed array and, multidimensional arrays and lists to eventually find the Dictionary Type, very powerful, and you can link it with objects/classes and lists to extend it. Essentially I was running a SQL query where I am building a complex table using a number of conditions, and could not use GridView because of that. But I also wanted a total at the bottom. So created a Total Table in the asp page. Then in the code file this is what I added: class ItemTotals {   public string ItemDesc { get; set; }   public double TotalsQty { get; set; } } //---- // code to run query... which returns into oleData //---- string _strItemDesc = oleData["ItemDesc"].ToString(); if (sumItemTotals.ContainsKey(_strItemDesc)) {    sumItemTotals[_strItemDesc].TotalsQty += Conver...

Serious do we always have to go back wards? PHP is rubbish

I have been programming on and off since I fell out of my teens. In those days languages where showing some sign of maturity. Pascal had shown the way of what a types language could achieve, to the point that a scratchy language called "B" had borrowed from this language to become "C". With in a decade another language called basic had borrowed from Pascal to become Visual Basic. SmallTalk was showing the way, showing how objects to help with re-usability and ease of use and understanding. And it had resulted in object pascal and C++ in the early 90's. And I thought that languages where showing that they could leave behind their ugly past based in COBOL and Fortran and its even uglier sisters like RPG. Unfortunately the quest to win the rat race took me away from programming as the GUI and web started to take hold. But in the last 5 years I have got back into programming par time. Initially just in VBA and access, but then C# for...

A simple how to export from TableAdapter to XML file

I recently wanted to import data from an existing system that is written in Access. The system allows for XML imports. Since I needed to do some background programming on the system, I opted to rather to it programmatically than use the standard export, since I would have to do it a few times, and also manipulate the data once it was imported and then exported. I struggled to find information on how to do this, so eventually decided to figure it out myself and this is how I did it: In Visual Studio I created a new project I added Connected to Access database using the Database Explorer, this created a link in the App_Data folder Then on the default page I allowed the user to place the file name, I then added a new DataSet, created a new TableAdapter, put the query I needed in there and Then in my code I exported to XML So the in Default.aspx It looks like this: File to Export to: < asp : TextBox  ID ="tbxCustomersToXML"  runat ="server" Width =...

Visual studio keeps saying "Make sure that the class defined in this code file matches the 'inherits' attribute"

Ever time I built my ASPX c# project the build would give an error saying: "Make sure that the class defined in this code file matches the 'inherits' attribute" I check and it did, I deleted the file and recreated it and still the same problem.The compiler was talking rubbish, and it was delaying me when I was debugging. I copied and pasted the  <%@ Page  tag, and check it. Eventually I though to myself lets think out the box here. It is telling us it does not match, what are the options: The page used to have and _default the definition and somewhere in the project it is finding it (so I did a porject wide search for these, and I did find a few funnies, re built and still same friggin error. The I though lets look for a file that is also referring to the background file, I had copied and pasted a few things, perhaps that was the problem, so I did a search the the full name of the  CodeFile , and that is when I found that another page I had renamed had ...

POST as form using C# to Pay Provider

The Remote Post Form class I have used the code for the jigar site and added my own goodies, so all credit to him. Sorry about the flast formating but is the only way I could get a neatish post using System; using System.Collections.Generic; using System.Web; using System.Security.Cryptography; /// <summary> /// Remotely handle and Post form from http://www.jigar.net/articles/viewhtmlcontent78.aspx%20 /// </summary> public class RemotePost { private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection(); public string Url; public string Method; public string FormName; public RemotePost(string pURL) { // // TODO: Add constructor logic here // Url = pURL; Method = "post"; FormName = "frmRemotePost"; }   public void Add(string name, string value) { Inputs.Add(name, value); } public void Post...