Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Johan Plesner Hamann 105 posts 199 karma points
    Aug 30, 2011 @ 21:49
    Johan Plesner Hamann
    0

    how to use SqlHelper and read table data

    I want to read data from a custom table, from umbraco´s databace.

    I am using a UserControl, csharp.

    But I can figure this out, I have searched all day long.

    I have found something about SqlHelper, but I can´t find documentation on this subject.

    thank you,
    - Johan

     

     

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Aug 31, 2011 @ 09:13
    Richard Soeteman
    1

    Hi Johan,

    Below is an example I use to retrieve data. Basically you pass in an SQL statement and paramters and it will return an IRecordsReader. If you don't care about compatibility with other datasources such as mysql you can use any database technique you like. It's just asp.net

    Cheers,

    Richard

      public List<ContentValidationErrorView> GetAll()
            {
                List<ContentValidationErrorView> validationErrors = new List<ContentValidationErrorView>();
                using (var reader = Application.SqlHelper.ExecuteReader("SELECT SEOAnalyzer_ValidationIssues.*,umbracoNode.Text AS DocumentTitle  FROM SEOAnalyzer_ValidationIssues INNER JOIN umbracoNode ON SEOAnalyzer_ValidationIssues.DocumentID = umbracoNode.id WHERE Ignore = 0 and ItemType='content' order by documentTitle, ValidationComponentAlias"))
                {
                    while (reader.Read())
                    {
                        validationErrors.Add(new ContentValidationErrorView(reader.GetInt("IssueId"))
                        {
                            DocumentID = reader.GetString("DocumentID"),
                            DocumentTitle = reader.GetString("DocumentTitle"),
                            Ignore = reader.GetBoolean("Ignore"),
                            IssueAlias = reader.GetString("IssueAlias"),
                            ValidationComponentAlias = reader.GetString("ValidationComponentAlias"),
                            Item = reader.GetString("Item"),
                            ItemText = reader.GetString("ItemText")
                        }
                        );
                    }
                }
                return validationErrors;
            }
  • Johan Plesner Hamann 105 posts 199 karma points
    Aug 31, 2011 @ 10:44
    Johan Plesner Hamann
    0

     Thank you Richard

    I am not an advanced user of csharp, but I'm glad for your help.

    I ended up with this and it is just what I needed 

     var reader = umbraco.BusinessLogic.Application.SqlHelper.ExecuteReader("SELECT * FROM jhName");
     while (reader.Read())
     {
      Label1.Text += reader.GetString("Name");
     }

     if you have any more tips I would greatly appreciate it.

    /Johan

     

     

     

  • Johan Plesner Hamann 105 posts 199 karma points
    Aug 31, 2011 @ 15:10
    Johan Plesner Hamann
    1

    If others lack information about working a bit with Umbraco database

            protected void Button1_Click(object sender, EventArgs e)
            {
    
                var sqlHelper = umbraco.BusinessLogic.Application.SqlHelper;
                var reader = sqlHelper.ExecuteReader(
                            @"SELECT * FROM 
                jhName WHERE Name = @Name AND pass = @pass",
                            sqlHelper.CreateParameter("@Name", TextBox1.Text),
                            sqlHelper.CreateParameter("@pass", TextBox2.Text)
                         );
    
    
                if (reader.Read())
                {
                    Response.Write(reader.GetString("Name")+" ");
                    Response.Write(" ok brugernavn eller kodeord.");
                }
                else
                {
                    Response.Write("Forkert brugernavn eller kodeord.");
                }
            }

    /Johan

  • bobby96333 1 post 21 karma points
    Feb 01, 2012 @ 02:04
    bobby96333
    0

    visite thw WebSite:http://www.dbhelper.org/sqlhelper/,download the code package.

  • Max 144 posts 166 karma points
    May 01, 2012 @ 10:35
    Max
    0

    how to select all and  display in gridview control

     

Please Sign in or register to post replies

Write your reply to:

Draft