.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

rand function problem

Posted By:      Posted Date: October 17, 2010    Points: 0   Category :ASP.Net
 

Hi,

i use the following code which loops through the numbers of a listbox and adds records to a database

in the db i use the rand function to add a unique id to msgID field which accepts unique values

but when the records are more than 1 or 2 i get error which says Cannot insert duplicate key row in object

which means the rand function adds the same values

how should i solve the problem??

IF EXISTS (SELECT * FROM sysobjects   WHERE name = 'Message'   AND type = 'P')
DROP PROCEDURE Message
GO

CREATE PROCEDURE Message
  @Message ntext
AS
  SET NOCOUNT ON
   
  Insert into CmmNet_inbox (MsgID,Message) values (round(RAND()*10000000000,0),@message)
GO

  Dim ctr As Integer
                    For ctr = 0 To ListFriends.Items.Count() - 1
                        If ListFriends.Items(ctr).Selected Then
                                  


View Complete Post


More Related Resource Links

EF 4: Function Import problem with Stored Procedures

  

I have the following SP which includes a temp table:

 DECLARE @pos int

--create table to hold parsed values
CREATE TABLE #list (val varchar

datalist printOut() function Problem

  
  • i m using below code..by using it i able to write asp data into word file n format it.but i m facing problen in print out..

    it show exception

    Message = "The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))"

    please hav a look at below code....

  •  .................div data...................   
  •   <div id="printdiv" runat="server">   
  •     <table style="border: 5px solid #FF00FF; width:100%">   
  •     <tr>   

  • table valued function problem

      
    This is my table-valued function Problem is it is returning only 1 record but it is supposed to return more than one i stuck with this problem plz replyALTER function [dbo].[funcqidata](@dst int,@mth int,@yer int) returns @cqi_rpt table ( hosp_name varchar(100) NULL, bedded_strength int NULL, out_patients int NULL, in_patients int NULL, minor_surgeries int NULL, major_surgeries int NULL, deliveries int NULL, radio int NULL, lab_test int NULL, tot_part1 int NULL, waste_man int NULL, swab_test int NULL, attendence int NULL, drug int NULL, charges_thismonth int NULL, charges_lastmonth int NULL, usr_charges_marks int NULL, tot_part2 int NULL --grand_tot int NULL ) as BEGIN DECLARE @hosp_name varchar(100), @bedded_strength int, @out_patients int, @in_patients int, @minor_surgeries int, @major_surgeries int, @deliveries int, @radio int, @lab_test int, @tot_part1 int, @opd_handled int, @opd_target int, --------- supporting variables declared for calculation ----------- @ipd_handled int, @ipd_target int, @minor_handled int, @minor_target int, @major_handled int, @major_target int, @delivery_handled int, @delivery_target int, @radio_handled int, @radio_target int, @lab_handled int, @lab_target int, -------- end of declaring variables ----------------------------- @check_charges int, @waste_man int, @swab_test int,

    Problem with appointment function

      
    I am beginner of asp.net and c#Currently i am learning on create a website with appointment feature. The website i am doing basically a dental appointment web, which show the free slot of dentist on the website and enable patient to book appointment by schedule an appointment based on time and date given. I have done others thing such as register, login, report those however i have no idea on doing the appointment module. I am trying to learn easy way to create booking feature for dental website. Is that a tutorial on learning to do this or others way which i can easily learn it. Thank you.

    Problem with IndexOf function in Java script?

      

    Hi all,  i have one problem while using Index Of function in java script. I am using this in this way:

    var ss=(document.getElementById('<%=HiddenField1.ClientID%>').value.indexOf(","+document.getElementById('<%=yyy.ClientID%>').value+"-"+document.getElementById(str).value,20));                       
                            if(ss==-1)
                            {
                                document.getElementById('<%=HiddenField1.ClientID%>').value+=(","+document.getElementById('<%=yyy.ClientID%>').value+"-"+document.getElementById(str).value);
                                countstore++;
              &nbs

    Problem with WCF CallBack function

      

    Hi,

    I have a problem with WCF CallBack function (DuplexChannel). The main problem is that when I invoke that method on the client I got a message format like that below:

    <ClientCallBackFunc xmlns="http://tempuri.org/ ">
      <issueId>1</issueId>
      <agreementId>2</agreementId>
      <limitId>3</limitId>
    </ClientCallBackFunc>

    where ClientCallBackFunc is name of callback method.

    I made service:

    public interface IClientCallBack

    {

         [OperationContract(IsOneWay=true)]

        void ClientCallBackFunc(string IssueId, string AgreementId, string LimitId);

    }

     

    [ServiceContract(CallBackContract=typeof(IClientCallBack)]

    public interface IService

    {

        string ServerMethod(string IssueId, string AgreementId, string LimitId);

    }

    but I should prefer to get like this:

    <HEADER>

    <SERVICE>Loans.Collateral.Verify</SERVICE></HEADER><DATA>

    <RESPONSE><ISSUE_ID>1</ISSUE_ID><AGREEMENT_ID>2</AGREEMENT_ID><LIMIT_ID>3</LIMIT_ID></DATA></RESPONSE>

    So, when I want send message from server side (callba

    function problem

      

    hi,

    i have the following function in my app_code which gets the data from database with datareader

    now on anothe page i need to output all of the data to a label

    i do not want to use datalist or gridview

    hwo should i do this?

    the function loops through the data ,i can put the function on the same page and use label.text += mydata

    but since it's a function and i want to use it on other pages how is it possible?

    Public Function getMembers(ByVal userID As Integer) As Boolean
                Dim Conn As New SqlConnection(HttpRuntime.Cache("con"))
                Dim dr As SqlDataReader
                Dim strSQL As String
                strSQL = "select * from test "
                Dim cmd As New SqlCommand(strSQL, Conn)
                cmd.Parameters.Add(New SqlParameter("@userID", userID))
                Conn.Open()
                dr = cmd.Execute

    Problem with ISNumeric function in SQL Server 2005

      

    Even though the system function IsNumeric('2,344') returns a true in SQL Server 2005, why does the following throw an error? Is there a special way to cast to numeric types in SQL Server 2005, so the statement below does not throw an error?

    SELECT  CASE ISNUMERIC('2,3444')
              WHEN 1 THEN CAST('2,344' AS INT)
              ELSE NULL
            END


    Searching Function Problem - Setting up indexer

      

    How do you set up an indexer for Sharepoint 2010 Foundations?


    Awesome HTML minifying function but causes problem at Google Adsense ads - Very Important !

      

    function works perfectly. everything works without any problem and source code becomes single line. but problem is about adsense ads. it is getting messed at screen.

     

    ads are displayed but their locations are not correct. can anybody help me i appricate that alot

     

    thank you

     

        protected override void Render(HtmlTextWriter writer)
        {
            if (this.Request.Headers["X-MicrosoftAjax"] != "Delta=true")
            {
                System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"<script[^>]*>[\w|\t|\r|\W]*?</script>");
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                System.IO.StringWriter sw = new System.IO.StringWriter(sb);
                HtmlTextWriter hw = new HtmlTextWriter(sw);
                base.Render(hw);
                string html = sb.ToString();
                System.Text.RegularExpressions.MatchCollection mymatch = reg.Matches(html);
                html = reg.Replace(html, string.Empty);
                reg = new System.Text.RegularExpressions.Regex(@"(?<=[^])\t{2,}|(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,11}(?=[<])|(?=[\n])\s{2,}|(?=[\r])\s{2,}");
                html = reg.Replace(html, string.Empty);
                reg = new System.Text.RegularExpressions

    Awesome HTML minifying function but causes problem at Google Adsense ads - Very Important !

      

    function works perfectly. it makes source code single line. but problem is about Google Adsense ads. their locations get messed up. what might be the reason ?

    programming language is c# asp.net 4.0

    here the function

     

     

      protected override void Render(HtmlTextWriter writer)
      {
        if (this.Request.Headers["X-MicrosoftAjax"] != "Delta=true")
        {
          System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"<script[^>]*>[\w|\t|\r|\W]*?</script>");
          System.Text.StringBuilder sb = new System.Text.StringBuilder();
          System.IO.StringWriter sw = new System.IO.StringWriter(sb);
          HtmlTextWriter hw = new HtmlTextWriter(sw);
          base.Render(hw);
          string html = sb.ToString();
          System.Text.RegularExpressions.MatchCollection mym

    Problem in calling javascript function from code behind

      

    Hi All,

      how can i call Javascript function on Button click after doing some server side operation?

      Though i am using ClientScript.RegisterStartupScrip(), sometime it is working(for alert) but when i am using for display confirm message it is not showing Confirm message.

    ClientScript.RegisterStartupScript(GetType(), "ConfirmMessage", "javascript:return ConfirmMessage('" + lMessage + "');");

    this is not working.


    Please help me out.


    Thanks & Regards,

    Joyanta

      


    Dynamic data and Entity framework problem when using a function in RegisterContext

      

    I am trying to use asp.net dynamic data using entity framewrok. my entity framework (edmx file) is in another dll and I dont want to put connection string in config files.
    I use this code to register my objectContext in global.asax:

    model.RegisterContext(() => new MyObjectContext("EntityConnectionString"), new ContextConfiguration() { ScaffoldAllTables = true });

    the first page (the list of tables) is ok, but when i click any table, i get this error:

    The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

     it seems that for the second request, it checks the web.config to look for entity connection string.

     


    Function pulls PCs along with users. Wrong Class? Problem with AD setup?

      

    I am creating a web app that interacts with AD. The issue that I have is I am trying to get all users in our domain  and the code I'm using seems to pull all the users however is also seems to be pulling all the PC names as well and I cannot seem to figure out why. Not sure if this will tell you anything but the PC names seem to be ending with a $ sign. ie a PC named LAB comes out in my list as LAB$.

        Public Function UpadateEmployees() As Boolean
            Dim boolreturn As Boolean
            Dim strADUser As String = ConfigurationManager.AppSettings("ADUser")
            Dim strADPass As String = ConfigurationManager.AppSettings("ADPassword")
            Dim entry As New DirectoryEntry(_path, strADUser, strADPass)
            Dim search As New DirectorySearcher(entry)
            search.Filter = "(objectClass=User)"
            search.PropertiesToLoad.Add("sAMAccountName")
            search.PropertiesToLoad.Add("givenName")
            search.PropertiesToLoad.Add("sn")
            search.PropertiesToLoad.Add("mail")
            search.PropertiesToLoad.Add("department")
    
            ' Declare objects
     
            ' Loop
            For Each result As SearchResult In search.FindAll()
                Try
    
                    Dim dirEntry As Directory

    Grand total problem using sum(descedant) function

      

    Hi there:

    I use the sum descendant function to sum the employees that has a sale using the following MDX

    Employee with sale =

    Sum(
    Descendants([Employees].[Employees].CurrentMember,,LEAVES)
    ,[Measures].[Employee wSales Count1]
    )

    The result is like this if I have all job category selected.

    Employee Group

    Employee Count

    Employee with sale

    difficult problem using useful function of MVC and EF4 together in nlayer-app

      

    Suppose such nlayer: mvc client <--> application layer <--> Domain layer <--> repository layer .

    reposiroy layer : ef4 model is in this layer used for ORM.

    Domain layer : the entities generated from ef4 model is in this layer.  all business logic realize in this layer.

    application layer: Show public interface to mvc client ,  and realize UnitofWork  to coordinate domain layer's function.

    My first problem is how can I use Attribute funtion which can be used by mvc for some useful function such as client validation, because in domain layer all entities code are generated from ef4 model automaticly , it's obvious that add Attribute to entity code is not a good way.

    So I reform any viewmodel that used by mvc client and application layer . Then add Attribute on viewmodel's property members. As times go on, I add more and more viewmodel. The most terrible problem is some viewmodel are so complex , it's so difficult to map from or to domain entity (or entities) and so difficult trace the relationship between viewmodels. 

    Any suggestion?


    Problem to group radio button across gridview rows

      
    In general no one can easily group or make a single selection from radio button list inside gridview rows. There are a lot of way to make a single or unique selection from list. Here i want to share how i can address this problem in the most easiest way. Googling the problem most of the cases i saw the grouping in horizontal way. Thats why i tried to group the radio buttons in vertical manner. Let i have a requirement like below:
    Categories: 
    ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
    Sql Server  SharePoint  Silverlight  Others  All   

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend