Friday, October 18, 2013

Lambda Expressions with JOIN in C#

Let us consider that we have two tables 
1.Login[Username,Password,ID as fields] and 
2.Salary[ID,Salary as Fields]

Open MS Visual Studio--> select ASP.Net empty website
Add--> 2 Gridviews and 1 Button
Add--> Linq to SQL from Data and give the name as TestOpportunity
Add the SQL Connection and then Drag and Drop the Tables[Login and Salary]

write the below code on Button1_click
TestOpportunityDataContext TODC = new TestOpportunityDataContext();
//var jointables = TODC.logins.Where(r=>r.ID>=3).Select(r => new {r.username,r.password,r.ID }).Where(r=>r.username.Contains("Sai"));
var  result= TODC.logins.Select(r => new { r.username, r.password, r.ID }).Where(r => r.username.Contains("Sai")).Distinct();
GridView1.DataSource = result;
GridView1.DataBind();

var jointables= TODC.logins.Join(TODC.Salaries, b => b.ID, c => c.ID, (b, c) => new { b.username,b.password,c.Salary1});
GridView2.DataSource = jointables;
GridView2.DataBind();

Friday, September 13, 2013

Assembly {0} does not contain a Web resource with name {0}

Assembly 'ABC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' contains a Web resource with name 'PasswordExtenderBehavior.js', but does not contain an embedded resource with name 'PasswordExtenderBehavior.js'.
for this we need to select "PasswordExtenderBehavior.js" right click and go to properties select BUILD Action-> Embedded Resource 

Friday, September 6, 2013

Open MS CRM Form in Classic Mode always

Add the below code in Ribbon button. Whenever you click on that button the form will open in Classic Mode

function openClassicForm() {
 var name =Xrm.Page.data.entity.getEntityName();
 var id =Xrm.Page.data.entity.getId();
  var clientUrl = Xrm.Page.context.getClientUrl();
  var url = clientUrl + "/main.aspx?etn=" + name + "&extraqs=%3fid%3d" + id + "%26&pagetype=entityrecord&rof=true";
  parent.parent.window.open(url);
}

Monday, September 2, 2013

Check the Username and Password from Active Directory

using System.DirectoryServices.Protocols;[Add this reference]

namespace Usernamepassword
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
              LdapConnection connection = new LdapConnection("domain.com");
              //Ex:Gmail.com
              NetworkCredential credential = new NetworkCredential("username", "Password");
                connection.Credential = credential;
                connection.Bind();
                Console.WriteLine("Succesfully Logged In");
                Console.ReadKey();
            }
            catch (LdapException msg)
            {
                String error = msg.ServerErrorMessage;
                Console.WriteLine(msg);
                Console.ReadKey();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
                Console.ReadKey();
            }
        }
    }
}

Wednesday, August 28, 2013

Convert .mdb to SQL database

There's also the SQL Server Import and Export Wizard 
  1. Open SSMS.
  2. Create a new empty database.
  3. Right-click the database in the Object Explorer.
  4. Select Tasks | Import Data... from the context menu.
  5. Change the data source to Microsoft Access.
  6. Browse for the file name.
  7. Click Next...
  8. That's it :-)

Tuesday, August 27, 2013

Create a Trigger

Create a trigger that will insert the old and new Passwords into a Table.
Open SSMS--Select database[Master]-->Select tablename[Logins]-->Expand the table--> you can find the Triggers-->select that and right click to create New Trigger--> change the trigger as we need
In this example below am showing how can we store/insert the Password into Audit table[Old/New].
Audit is the new table with columns[OldPassword,NewPassword,DateTime].
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,K.Sai Krishna Yadav>
-- =============================================
CREATE TRIGGER AuditInfo 
   ON  Login
   AFTER INSERT,DELETE,UPDATE
AS 
BEGIN
declare @OldValue Varchar(50)
declare @NewValue Varchar(50)
select @OldValue=password from deleted
select @NewValue=password from inserted
Insert into Audit(AuditInfo,OldValue,NewValue) values (GETDATE(),@OldValue,@NewValue)
SET NOCOUNT ON;
    -- Insert statements for trigger here
END
GO
The above Trigger will fire when an INSERT,DELETE,UPDATE happens on Logins Table.

Friday, August 9, 2013

Query to update multiple rows with particular data/string in SQL

update tablename set columnname=REPLACE(tablename.columnname,'string to search','string to replace')

Consider the below table with name 'Employee'
ID Name
1 sa
2 sa krishna
3 sa kumar
4 sa ganesh

After executing the update statement
update Employee set Name=REPLACE(Employee.Name,'sa','sai')  
then the final result will be
ID Name
1 sai
2 sai krishna
3 sai kumar
4 sai ganesh