Copied to clipboard

Flag this post as spam?

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


  • Rahul 12 posts 83 karma points
    Mar 13, 2014 @ 06:32
    Rahul
    0

    Custom Control with Data Base

    Hi All,

    I am new in Umbraco. I want to create custom contol for umbraco with database connectivity. 

    I have searched this on google but not found any thing regarding database connectivity.

    Please suggest...

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 13, 2014 @ 08:42
    Ismail Mayat
    0

    Rahul,

    What version of umbraco are you using? Also is the database a separate database from the umbraco database or is it a bunch of tables you want to query in the umbraco database that you have created?

    Regards

    Ismail

  • Rahul 12 posts 83 karma points
    Mar 13, 2014 @ 10:36
    Rahul
    0

    Ismail

    I am using Umbraco version 6.1.6. I have created tables in the Umbraco database.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 13, 2014 @ 10:49
    Ismail Mayat
    100

    Rahul,

    In that case you can make use of petapoco which is the data layer umbraco uses. More information about peta poco here and to use in umbraco you can do things like:

    Database Db = ApplicationContext.Current.DatabaseContext.Database;
    

    public bool InsertRecordInDb(int questionId, int nodeId, bool answer, Guid recordId) {
    var surveyEntry = new SurveyAnswer { ContourId = recordId, NodeId = nodeId, Answer = answer, QuestionId = questionId, DateOfAnswer = DateTime.Now }; try { Db.Insert(surveyEntry);

                return true;
    
            }
            catch (Exception ex)
            {
                LogHelper.Error<Exception>("Error inserting record " + surveyEntry.ToString(), ex);
            }
            return false;
    
        }
    

    and my class surveyanswer looks like:

        [TableName("SurveyAnswer")]
    [PrimaryKey("Id", autoIncrement = true)]
    [ExplicitColumns]
    public class SurveyAnswer
    {   
        [Column]
        public int Id { get; set; }
    
        [Column]
        public Guid ContourId { get; set; }
    
        [Column]
        public int QuestionId { get; set; }
    
        [Column]
        public int NodeId { get; set; }
    
        [Column]
        public bool Answer { get; set; }
    
        [Column]
        public DateTime DateOfAnswer { get; set; }
    
        public override string ToString()
        {
            return string.Format("Id: {0}, ContourId: {1}, QuestionId: {2}, NodeId: {3}, Answer: {4},DateOfAnswer:{5}", Id, ContourId, QuestionId, NodeId, Answer,DateOfAnswer);
        }
    }
    

    So my surveyclass maps to survey table in database.

    Regards

    Ismail

  • Rahul 12 posts 83 karma points
    Mar 13, 2014 @ 12:23
    Rahul
    0

    Thanks a lot Ismail

    I will try your solution and let you know if any help needed for the same.....

  • Divya 3 posts 23 karma points
    Apr 18, 2014 @ 08:53
    Divya
    0

    Hi,

    I am new in umbraco 7..... How to create Data base for umbraco 7 version.....

    i installed umbraco 7 using IIS.... but i didnot get the database details....

    Kindly provide the database details for Umbraco 7

  • Ghufran Ahmad 17 posts 73 karma points
    Feb 17, 2015 @ 12:02
    Ghufran Ahmad
    0

    First create a blank databsase at your local machine or server where you want to create database

    when you run the site through IIS there will be first step where you set the user daetails and also you will find 2 buttons: Continue another Customise 

    click on customise button in next screen you will find option to set database details.

Please Sign in or register to post replies

Write your reply to:

Draft