insert entity to database using sql stored procedure:Urgent

2 posts, 0 answers
  1. Derya Altuntas
    Derya Altuntas avatar
    5 posts
    Member since:
    Nov 2009

    Posted 20 Nov 2009 Link to this post

    I want to add a new entity to table which has relation to another table.I write an sql procedure to do this.But there is a coulum ın the table that in nvarchar.My stored procedure includes this.

    ALTER PROCEDURE [dbo].[sp_ins_Object_DIS] (@object_ID UNIQUEIDENTIFIER ,@category INTEGER , @country INTEGER , @domain INTEGER , @extra INTEGER , @kind INTEGER , @marking NVARCHAR , @specific INTEGER , @sub_category INTEGER) AS INSERT INTO [Objects_DIS] ( [object_ID] , [category] , [country] , [domain] , [extra] , [kind] , [marking] , [specific], [sub_category] ) VALUES ( @object_ID , @category , @country , @domain , @extra , @kind , @marking , @specific , @sub_category)

    I am calling this procedure from code by sending parameter but there is no equivalent for nvarchar in C#.ı want to sent textbox string value.It gives error.Please help.

    if (!m_scope.Transaction.IsActive)
                Platform selectedPlatform = (Platform)m_lbx_SAMPlatform.SelectedItem;

                string query = "SELECT * FROM ObjectsDISExtent AS c WHERE c.platform = $1";

                IQueryResult result = m_scope.GetOqlQuery(query).Execute(selectedPlatform);

                ArrayList resultSet = result.ToList();

                if (resultSet.Count > 0)//to change existing variables

                    ObjectsDIS platformDIS = (ObjectsDIS)resultSet[0];
                    platformDIS.Kind = m_cmbbx_SamKind.SelectedIndex;
                    platformDIS.Domain = m_cmbbx_SamDomain.SelectedIndex;
                    platformDIS.Country = Int16.Parse(m_txtbx_SamCountry.Text);
                    platformDIS.Category = Int16.Parse(m_txtbx_SamCategory.Text);
                    platformDIS.Specific = Int16.Parse(m_txtbx_SAMSpecific.Text);
                    platformDIS.SubCategory = Int16.Parse(m_txtbx_SAMSubCategory.Text);
                    platformDIS.Extra = Int16.Parse(m_txtbx_SamExtra.Text);
                    platformDIS.Marking = m_txtbx_SAMMarking.Text;
                else//insert new if there is no entity for selected platform.This gives error
                    IQuery newquery = m_scope.GetSqlQuery("sp_ins_Object_DIS ?,?,?,?,?,?,?,?,?",


                                             "GUID object_ID, INTEGER category, INTEGER country, INTEGER domain ,INTEGER extra, INTEGER kind, NVARCHAR marking,INTEGER specific,INTEGER sub_category");

                    IQueryResult newa = newquery.Execute(new object[] { selectedPlatform.Id, Int16.Parse(m_txtbx_SamCategory.Text), Int16.Parse(m_txtbx_SamCountry.Text), m_cmbbx_SamDomain.SelectedIndex, Int16.Parse(m_txtbx_SamExtra.Text), m_cmbbx_SamKind.SelectedIndex, m_txtbx_SAMMarking.Text, Int16.Parse(m_txtbx_SAMSpecific.Text), Int16.Parse(m_txtbx_SAMSubCategory.Text) });
                    int newcount = newa.Count;



  2. PetarP
    PetarP avatar
    754 posts

    Posted 25 Nov 2009 Link to this post

    Hi Derya Altuntas,

    Can you please try to change the string that declares the parameters needed by the stored procedure to look like this:
    IQuery newquery = m_scope.GetSqlQuery("sp_ins_Object_DIS ?,?,?,?,?,?,?,?,?", null,
                                            "GUID object_ID, INTEGER category, INTEGER country, INTEGER domain ,INTEGER extra, INTEGER kind, VARCHAR marking,INTEGER specific,INTEGER sub_category");
    As you can see I have changed the NVARCHAR declaration to VARCHAR one (note that the marking column is still NVARCHAR on the database side. This should solve your problem.

    Sincerely yours,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
Back to Top