Using SQL to pull Data

Original Post rayburrell's Avatar

rayburrell

01 Jun, 2010 09:33 PM via web

Hi all. I am fairly new at programming, and very new to fluent. I am trying to pull some data from my database using CreateSQLQuery(), and am not having much luck. If I want to pull all the data from my database that has unit field = Some value and a name field = "some value" what is the best way to accomplish that?

I was trying to use IQuery as so:

public static Pi_Tag GetTagByUnitAndName(int unit, string name)

    { 
        using (ISession session = DataConnector.Instance.sessionFactory.OpenSession())
        {
            IQuery query = session.CreateSQLQuery("SELECT * FROM pi_tag WHERE unit = " + unit.ToString() + " AND tag_name = " + name);

            Pi_Tag tag = (Pi_Tag)query.UniqueResult();

            return tag;
        }
    }

    Reply to this discussion

    Preview Comments are parsed with Markdown. Help with syntax

    Attached Files

      You can attach files up to 10MB

      Ten divided by two is what?

      Recent Discussions

      05 Jul, 2010 10:29 PM
      05 Jul, 2010 12:45 PM
      05 Jul, 2010 12:42 PM
      05 Jul, 2010 12:17 PM
      05 Jul, 2010 12:12 PM

       

      03 Jul, 2010 12:26 AM
      02 Jul, 2010 02:17 PM
      02 Jul, 2010 08:18 AM
      02 Jul, 2010 12:20 AM
      01 Jul, 2010 10:14 PM