Thursday, 3 February 2022

DNN delete all duplicated users

declare @email as nvarchar(256)

 

DECLARE db_cursor CURSOR FOR

SELECT [Email]

  FROM [Users]

  group by [Email] 

  having count([Email])>1

 

OPEN db_cursor 

FETCH NEXT FROM db_cursor INTO @email 

 

WHILE @@FETCH_STATUS = 0 

BEGIN 

    

         UPDATE dbo.UserPortals

                           SET

                                  IsDeleted = 1

                           WHERE  PortalId = 0

                           and UserId in (

SELECT [UserID]

  FROM [Users]

  where Email =@email and ([UserID] not in (SELECT [UserID]

  FROM [RelatedTable1]

  where [UserID] in(SELECT [UserID]

  FROM [Users]

  where Email =@email)

  UNION

  SELECT [UserID]

  FROM [RelatedTable2]

  where [UserID] in(SELECT [UserID]

  FROM [Users]

  where Email =@email))))

      FETCH NEXT FROM db_cursor INTO @email

END

 

CLOSE db_cursor 

DEALLOCATE db_cursor


Wednesday, 12 January 2022

globals.navigateurl is obsolete

 

DotNetNuke.Common.Globals.NavigateURL() in Dnn 8, but in DNN 9 use the following 


  • PortalSettings.ActiveTab.FullUrl to replace NavigateURL()
  • Response.Redirect(EditURL()) to replace NavigateURL() with parameters

Saturday, 11 September 2021

Loop through table in mssql

SET NOCOUNT ON

 

DECLARE @ParcelCode nvarchar(100)

 

DECLARE load_cursor CURSOR FOR

    SELECT [ParcelCode]

    FROM dbo.[Info_parcels05]

 

OPEN load_cursor

FETCH NEXT FROM load_cursor INTO @ParcelCode

 

WHILE @@FETCH_STATUS = 0

BEGIN

    BEGIN

              update [dbo].[Info_parcels05]

                           set PriceByHumen=(SELECT FLOOR(RAND()*(1000000))),PriceByMachine=(SELECT FLOOR(RAND()*(1000000)))

                           where ParcelCode=@ParcelCode

         

    END 

    FETCH NEXT FROM load_cursor INTO @ParcelCode

       print @ParcelCode

END

 

CLOSE load_cursor

DEALLOCATE load_cursor

GO


Saturday, 28 March 2020

C# Send Email


Use the following Code to send Email
protected void SendMail()
        {

            MailAddress from = new MailAddress("your_email@gmail.com");
            MailAddress toMail = new MailAddress(to.Text);
            MailMessage message = new MailMessage(from, toMail);
            message.Subject = subject.Text;
            message.Body = body.Text;
            message.IsBodyHtml = true;
            // Add a carbon copy recipient.
            var smtp = new System.Net.Mail.SmtpClient();
            {
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.UseDefaultCredentials = false;
                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtp.Credentials = new NetworkCredential("your_email@gmail.com", " YourPassword");
                smtp.TargetName = "STARTTLS/smtp.gmail.com";
                smtp.EnableSsl = true;
                smtp.Timeout = 100000;
            }
            try
            {
                smtp.Send(message);
                MessageBox.Show("Mail Sent");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error  :  "+ex.StackTrace);
            }
        }

Thursday, 21 November 2019

Error While Launching the activity

Android Studio

Error While Launching the activity



The solution:

The only one best Answer is to run uninstall command from adb and install the app again 

cd to 
C:\Users\YourUser\AppData\Local\Android\sdk\platform-tools>

run the following command 

adb uninstall applicationId 

applicationId: from gradle module file 

Saturday, 21 September 2019

How to export one table or sheet to multiple tables or sheets

If you have one excel sheet or table and you want to export it to multiple sheets or tables use the following steps:

  1. Specify the column -tablesNamesColumn- you want its data to be the names of the tables/sheets 
  2. import the main sheet to MSSQL 
  3. Select distinct values from the tablesNamesColumn
  4. Create a table and name it "TablesNames":                                                                                       CREATE TABLE [dbo].[TablesNames](
           [id] [int] IDENTITY(1,1) PRIMARY KEY,
           [Table_Name] [nvarchar](255) NOT NULL,
    )   
  5. insert the tables names in the table which contains the tables names                                               insert into TablesNames
    SELECT distinct tablesNamesColumn  
    FROM [AllSheets]
  6. Now you need to loop inside the tables names and create tables in the same format         
    DECLARE @LoopCounter INT , @MaxTablesNamesId INT,
            @TableName NVARCHAR(100)
    SELECT @LoopCounter = 0 , @MaxTablesNamesId = count(*)
    FROM TablesNames

    WHILE ( @LoopCounter IS NOT NULL
            AND  @LoopCounter <= @MaxTablesNamesId)
    BEGIN
       SELECT @TableName = Table_Name FROM TablesNames
       WHERE id = @LoopCounter
      -- PRINT @TableName 
       SELECT @LoopCounter  = min(id) FROM TablesNames
       WHERE id > @LoopCounter
      
    declare @q nvarchar(max) = '
    drop table ['+@TableName+'];
    SELECT * INTO  ['+@TableName+']
    FROM [delme]
    WHERE Institution = N'''+ @TableName +''';' 
    exec (@q)
    END
  7. Use the following steps to export the data to Excel 97-2003 file, because I tried Excel 2010 and 2016, the only one works fine is 97-2003