Allerablog

Code This

Identity Insert

clock December 27, 2008 14:53 by author dickersonka

A lot of times we have reference tables that are you used for constants rather than just actual data values.  By typical design you will have identity set for a table and won't be able to insert into a table with the identity seed set.

 To enable this in the sql server, its simple.

SET IDENTITY_INSERT TableName ON

 INSERT INTO TableName(ID_COLUMN, NAME_COLUMN) values (1, "Number One")

SET IDENTITY_INSERT TableName OFF

 Thats all there is to it.  Now you are able to insert into a table that has an autoincrementing identity.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


SQL Server Reset Identity

clock December 21, 2008 15:41 by author dickersonka

It has been much too long since my last post.  With the holidays coming sometimes, it is just hard to find the time.  Enough, with that here we go.

Lets say we have a list of 500 entries in the database with id's 1-500 (this could also be known as autoincrementing keys).  We deleted 250-500, yet when we insert a new record, the id will be at 501.   As far as the database side, this is perfectly fine, no need to tweak it.  But as humans, we like things to be in order, therefore we want to start renumbering at 250.

The important thing to make sure is that you have keys referenced from this, otherwise you will have records correlating to a newly inserted record, which has no data belonging to it yet.

I'm not saying this is the right thing to do, just a common solution to what you want to accomplish.

To check the next value of our table, we'll use this 

DBCC CHECKIDENT (tablename, NORESEED)

 To reset the value of our identity we'll use this

DBCC CHECKIDENT(tablename, RESEED, 250)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Syntax Highlighting with BlogEngine.net

clock December 1, 2008 10:24 by author dickersonka

I have found myself posting code recently and just didn't like the syntax highlighting provided as default with blogengine.net.  Nothing against these guys whatsoever, they make many people's lives much easier. 

 Here is what I use for code formatting.

http://www.codeplex.com/syntaxhighlighter

Currently these languages are supported

  • C#
  • JavaScript
  • HTML
  • MSH
  • T-SQL
  • Visual Basic
  • XML

this will allow your code to go from this

 public class MyClass

{
      private int myInt;
}

 

to go to this

public class MyClass

{

      private int myInt;

}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Sharing data between forms with C#

clock November 29, 2008 16:15 by author dickersonka

This shows how to share data between forms with C#.  It is a very common question that comes up quite frequently.    

I show how to pass data between forms with methods and properties (getters / setters).  Sharing data is not limited to these options, but these are the common techniques used to accomplish this.

public partial class frmInput : Form
    {
        public frmInput()
        {
            InitializeComponent();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //Set our variables from our input form
            string firstName = this.tbFirstName.Text;
            string lastName = this.tbLastName.Text;
            string sample = this.tbSample.Text;

            //Create an instance of the output form
            frmOutput frmOut = new frmOutput();

            //We set values through a property
            frmOut.Sample = sample;

            //We set values through a public method
            frmOut.SetDisplayValues(firstName, lastName);
          

            //We show the output form
            frmOut.ShowDialog();
        }
    }


public partial class frmOutput : Form
    {
        private string sample;
        //Getter / Setter for Sample
        public string Sample
        {
            get
            {
                return sample;
            }
            set
            {
                sample = value;

                //Set from property
                this.tbSample.Text = this.sample;
            }
        }

        public frmOutput()
        {
            InitializeComponent();
        }

        public void SetDisplayValues(string firstName, string lastName)
        {
            //Set from method
            this.tbFirstName.Text = firstName;
            this.tbLastName.Text = lastName;
        }
    }

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


MySql Joins (Inner join, left join)

clock November 21, 2008 17:07 by author dickersonka

First post, why not start with mysql and joins.  A topic many people with have trouble with.

 Lets say we have two tables,  users and users_preferences

users

USER_ID

USER_NAME

USER_PASSWORD

user_preferences

USER_PREFERENCE_ID

USER_ID

IS_ADMIN

IS_POWER_USER

to get information for users that have preferences already we can do this INNER JOIN

select u.USER_ID, u.USER_NAME, u.USER_PASSWORD, up.IS_ADMIN, up.IS_POWER_USER

from users u

inner join user_preferences up

on up.USER_ID = u.USER_ID

perfect except what if the user doesn't have an entry in the userpreferences table yet,

simple, we'll just do left join

select u.USER_ID, u.USER_NAME, u.USER_PASSWORD, up.IS_ADMIN, up.IS_POWER_USER

from users u

left join user_preferences up

on up.USER_ID = u.USER_ID

notice the small difference of inner to left

inner requires the entries to be in both tables, while a left join requires the entry only to be in the left table (users)

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Arrays and ArrayList

clock November 20, 2008 20:19 by author dickersonka

Arrays are fixed size holders of objects, and arraylists are dynamic.

Array

int[] intArray = new int[3];

intArray[0] = 1;

intArray[1] = 2;

intArray[2] = 3;

 

ArrayList intList  = new ArrayList();

intList.Add(1);

intList.Add(2);

intList.Add(3);

the arraylist allows much more flexibility, drawback is it takes up just a bit more memory, like we would ever notice nowdays anyway

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Welcome

clock November 19, 2008 23:03 by author Administrator
Welcome to the blog.  Hope that at least for some of you will you find this useful.  I have been helping a lot of people with programming problems / ism's for a while and decided, it would be beneficial to others.  Have any tips or questions for me, feel free.  Would love to hear from you.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Welcome to BlogEngine.NET 1.4.5

clock June 28, 2008 18:00 by author Administrator

If you see this post it means that BlogEngine.NET 1.4.5 is running and the hard part of creating your own blog is done. There is only a few things left to do.

Write Permissions

To be able to log in to the blog and writing posts, you need to enable write permissions on the App_Data folder. If you’re blog is hosted at a hosting provider, you can either log into your account’s admin page or call the support. You need write permissions on the App_Data folder because all posts, comments, and blog attachments are saved as XML files and placed in the App_Data folder. 

If you wish to use a database to to store your blog data, we still encourage you to enable this write access for an images you may wish to store for your blog posts.  If you are interested in using Microsoft SQL Server, MySQL, VistaDB, or other databases, please see the BlogEngine wiki to get started.

Security

When you've got write permissions to the App_Data folder, you need to change the username and password. Find the sign-in link located either at the bottom or top of the page depending on your current theme and click it. Now enter "admin" in both the username and password fields and click the button. You will now see an admin menu appear. It has a link to the "Users" admin page. From there you can change the username and password.  Passwords are hashed by default so if you lose your password, please see the BlogEngine wiki for information on recovery.

Configuration and Profile

Now that you have your blog secured, take a look through the settings and give your new blog a title.  BlogEngine.NET 1.4 is set up to take full advantage of of many semantic formats and technologies such as FOAF, SIOC and APML. It means that the content stored in your BlogEngine.NET installation will be fully portable and auto-discoverable.  Be sure to fill in your author profile to take better advantage of this.

Themes and Widgets

One last thing to consider is customizing the look of your blog.  We have a few themes available right out of the box including two fully setup to use our new widget framework.  The widget framework allows drop and drag placement on your side bar as well as editing and configuration right in the widget while you are logged in.  Be sure to check out our home page for more theme choices and downloadable widgets to add to your blog.

On the web

You can find BlogEngine.NET on the official website. Here you'll find tutorials, documentation, tips and tricks and much more. The ongoing development of BlogEngine.NET can be followed at CodePlex where the daily builds will be published for anyone to download.

Good luck and happy writing.

The BlogEngine.NET team

Currently rated 4.4 by 3 people

  • Currently 4.4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5