Showing posts with label software. Show all posts
Showing posts with label software. Show all posts

Difference between inner and outer join in SQL

Assume you have two tables A and B.

Inner join of A and B gives the intersect of A and B. Inner join requires atleast one match in both tables. (i.e., in A and B)


Outer join of A and B gives the unoin of A and B. Outer join returns all the record from the left table even though they don't have any common record.



Example:

Assume you have two tables A and B. Both tables have one column in common:

Table A Table B

A     B

ID     ID
1     6
2     1
3     5
4     2

Inner join :

It results the intersection of the two tables, i.e. the two rows they have in common.

select * from A INNER JOIN B on A.ID = B.ID;

The result will be...
1  1
2  2

Left outer join :

It will return all rows from A , plus any common rows from B.

select * from A LEFT OUTER JOIN B on A.ID = B.ID

Result :
1   1
2   2
3   null
4   null


Full outer join :

It will return the union of A and B, i.e. All the rows in A and all the rows in B.

select * from A FULL OUTER JOIN B on A.ID = B.ID;

   1      1
   2      2
   3     null
   4     null
  null    5
  null    6

Read more...

Return only one result from LINQ Query

You can do it in two ways, either use First or use Single.

First returns only first row, even there are multiple rows

Single expects only one row to be returned, and if there are multiple rows, it throws exception.

So, use Single if you are expecting only one row to be returned.

EX: var book= from book in store where (book.price > 100) select book).First();
Generally , the query returns all books having price greater than 100. but , as we are using  " .First() " only first book will be returned.


Read more...

return more than one value from a method


We can't return more than one values from a method.

An alternative way would be, add all those values to be returned into  Array and return that array.

Ex: public int[] returnArray ()
{
int[] myArray=new int[3];
myArray[0] = value1;
myArray[1] = value2;
myArray[2] = value3;

      return myArray;
}

Read more...

Collection was modified; enumeration operation may not execute c#


You will get this error when you are trying to remove list item in foreach loop.

either you have to use removeAll or removeAt.

It's good to iterate backward by index. like below,

for(int i = list.Count - 1; i >= 0; i--)
{
 if({some condition})
    list.RemoveAt(i);
}

Read more...

Initialize list with size in c#


public static List<t> listitems = new List<t>(10);

It just creates a list with maximum capacity 10, but the count will be 0 only. It means the list is still empty.

If you want to create a list without any size, you can do it like this,

public static List<t> listitems = new List<t>(10);

Read more...

Sending email with attachments from C#


In many cases you may required to send emails using ASP.NET. You can have all the classes required to send an email in the System.Net.Mail namespace. You can send an email from ASP.NET as follows :

First you have to add these namespaces to your code behind file:

1. using System.Net;
2. using System.Net.Mail;

Then write the following method

public void email_send()
{
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    mail.From = new MailAddress("your [email protected]");
    mail.To.Add("[email protected]");
    mail.Subject = "Test Mail - 1";
    mail.Body = "mail with attachment";

    System.Net.Mail.Attachment attachment;
    attachment = new System.Net.Mail.Attachment("c:/textfile.txt");
    mail.Attachments.Add(attachment);

    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("your [email protected]", "your password");
    SmtpServer.EnableSsl = true;

    SmtpServer.Send(mail);

}

Using the above you can send attachemebts also. Hope this helps :-)
Read more...

No connection could be made because the target machine actively refused it 127.0.0.1:4444

I had this issue and it took a lot of time to find the solution for this. I searched many sites for the solutions. After few hours, i have found the solution for this issue. (This is the solution which worked for me . I hope this will work for others also.)

The problem is i din't start the selenium server. After starting the server, issue gone and all worked fine.

You can download selenium server here. Download Selenium server

After downloading start the selenium server. See screen shot below


Read more...