WHAT'S NEW?
Loading...

Disclaimer


This blog is mainly intended for my own references and other belongings I may need to remember. However, if the information is relevant on what you search for that can be found on this blog, then that’s great! All I had posted here are my collection works in different programming languages and other stuffs that I had been contributed on the internet. If you would like to contribute with commentary or additional information in my post, then that is great so that it can improve it as well.

In general, I only provide views and opinion based on what I had learned that I had been contributed from the internet and not compensated to provide opinion on services, products, and other various topics. Any provided information does not accept accountability for content hosted and will not be detained responsible.

This blog uses third party advertisement for maintenance support of my blog such as Nuffnang program and Infolinks.

For any questions about this blog, kindly email me @ fegaridoj@gmail.com just to let me know about your questions or suggestions.

Hopefully this blog brings you new learning’s and expands your ideas. Thank you for visiting!

How to lock specific cell in Excel worksheet


The problem that I was encountered when someone asking about excel is how to lock specific cells in excel, because he want to know how to secure the confidentiality if somebody wants to modify the data in a worksheet particularly for specific rows and columns. Unfortunately, he’s question didn’t yet answer when he left because I have no idea answering his problem. I used search engine to find specific answer for the problem to help him, it’s sad to say that I am computer literate but I couldn’t find the solution for that simple problem.

I guess it’s a challenge for me. So, I wrote this article because finally I found it how very simple is. Hopefully this is very helpful for someone looking the same problem. Unfortunately, I used 2007 version, I think it’s similar in 2010 version of Excel.

To start – Open Microsoft Excel. Highlight the entire worksheet or Press Ctrl + A then Right click anywhere in the worksheet and click Format Cells






















After that, dialog box appear. When you not using often, the default tab is Number, switch to Protection.
























When you noticed we have 2 options, Locked and Hidden. Uncheck Locked so that we can apply only specific cells security. Then OK.










Now, it looks like the example above. However, is not the end to lock specific cell. Try to type any words in your worksheet let say “Hello” anywhere in column or rows. Ok, we are going to lock only Hello in a specific cell.






























Again, right click on “Hello” word and select Format as what we did in previous. Noticed, in protection tab, all option now is uncheck. Check the option Lock.
























Click OK. Make sure the mouse pointing in “Hello” word. In the ribbon area, the default is Home Tab. Toggle to Review Tab and select Protect Sheet.
























Now type the password you want. Note: No need to check other options, just follow the default value given. Try to change the name “Hello”.










This dialog box display read – only because you don’t have permission to change it. In order to change the value, click Review Tab and click Unprotect Sheet.
















Type your password. Now you may able to modify your record.

Now, you can create your records in excel and restrict those important cells you wish to add permission.

Here is the Video Tutorial


That’s all! Hope this is very helpful. 

About Author - Tesear.Com


I am having fun in blogging to post my own articles in providing relevant information and source code on different concepts in programming and other stuffs that might be helpful to the viewers. The intended of this blog is the availability that visible as my future references at the same time to the readers who want to learn basic programming subject.

Actually, I am a programmer want to acquire knowledge in different level of programming concepts that might not yet been discover. All this hard work accomplishment based on my basic knowledge of understanding and learnings.

About the author of this blog – tesear.blogspot.com is own by Joannou H. Fegarido, a Computer Professor @ Colegio de la Purisima Concepcion Roxas City, Capiz, Phillipines. So, I came at this point to post important things to remember because not all the things you had learned/discovered could be remembered.

Thank you for visiting this blog. Hope you will find relevant information! Keep on visiting often.

Just email @ fegaridoj@gmail.com to affiliate from this blog.

~Jocode~


Insert record into multiple tables using LINQ


This tutorial not only covers how to insert record into multiple tables using LINQ but also includes how select, join tables to display in DataGridView and search record in related tables. In order to achieve this tutorial, first you have already installed Visual Studio in your computer with C# language, however LINQ doesn’t support lower version of .NET. The version I already used in this tutorial is the latest version of Visual Studio 11 which is now available in Beta, unfortunately there’s a lot of feedback in comes the color of an icons because they didn’t like the appearance the way how it looks and color is very important to distinguish which icon is necessary to use unlike previous versions of Visual Studio. Indeed, Visual Studio 11 has more features added that meets the need of every developers, however only Windows 8 has the power to achieve the fully features of VS11.

The database I used to store data is SQL Server that’s provided by Visual Studio 11.






















This is the start page of Visual Studio 11.

To start, create new project – select C# for language to use and click Windows Form Application. The form should looks like the following.


















This form serves as template throughout this tutorial.

Now, we are going to setup our SQL Server connection in order to create a table. On your Data Connections, you are going to create New Connection Server Database which is the name of your server. After connection was established, Data Connection looks like the following.






















It belongs to the Server Explorer our database. We need only Database Diagrams to create our relationships and Tables which we are going to work with to create 2 tables. We need to create a table name tblinfo and tblorder where tblinfo is a foreign key to the tblorder table.

To create table, right click on Tables and Add New Table. Write the column name ID, Firstname, Lastname, and Gender, take note, we need to auto increment the ID so that every time we add new record it will automatically generated new ID number.

















In order to generate auto increment, in Column Properties locate the Identity Specification, the default value is No, change it to Yes. Save it as tblinfo.

Next, create another table where tblinfo is the foreign key to tblorder. Set the column name ID and set as auto increment the same as we did in tblinfo, InfoID is the foreign key from tblinfo ID, and ProductName.
Now, you’ve already tables.















We need to distinguish the relationship, in Database Diagrams right click then Add New Diagram and Add the following tables. The diagram now looks like the following.















Now, simply drag the ID from tblinfo to tblorder infoID. When you noticed while creating a relationship, there’s dialog box appear that place which table you want to enforce relationships. Now it’s look like the following.















Make sure to name the diagram before closing. Now, we have done to create tables and creating relationships.

It’s now to create our Database Model (DBML) LINQ to SQL classes mapped to relational object enable to query data from database source. In order DBML available, in solution explorer right click the name of your project name and Add – New Item. When dialog box appear, select LINQ to SQL Classes then name it DBinfoClass and DBML looks like the following.



















Now, from Server Explorer drag the Tables tblinfo and tblorder to design surface.


















It’s now generating relational database. It’s easy for programmer to write the code once the databases already normalized.

LINQ is a powerful language to write less code that generates quick result because table is no longer to use instead table treated as an objects to query data from database. Let’s take a look how LINQ works!
public static DBinfoClassDataContext db = new DBinfoClassDataContext();

We create new instance of object. Noticed, no need to configure database connection however, you can manually write the connection string where your database path save.

Example: string con = "your connection path";
         public static DBinfoClassDataContext db = new DBinfoClassDataContext(con);

Next, we are going to Insert/Add new records to our database but we have to insert it once with two tables. I made this as my own method to insert record into two related tables. Here we go! Double click the save button and copy this code.

     tblinfo tableInfo = new tblinfo
            {
                Firstname = txtfirstname.Text,
                Lastname = txtlastname.Text,
                Gender = cbGender.Text
            };

            db.tblinfos.InsertOnSubmit(tableInfo);
            db.SubmitChanges();

            tableInfo.ID = tableInfo.ID;//ID to be inserted to Order table

            tblorder tableOrder = new tblorder
            {
                InfoID = tableInfo.ID,
                Productname = txtproduct.Text
            };

            db.tblorders.InsertOnSubmit(tableOrder);

            db.SubmitChanges();
            MessageBox.Show("Saved");

This is just how LINQ syntax works to add new record, simply simple. Next, double click load button to load data to DataGridView.

   var load = from queryInfo in db.tblinfos
                     join queryOrder in db.tblorders
                     on queryInfo.ID equals queryOrder.InfoID
select new { queryInfo.Firstname,queryInfo.Lastname,    queryOrder.Productname };

            dataGridView1.DataSource = load;
When you noticed the syntax, it’s clean and easy to understand the way how LINQ join two tables. Next, to search record, double click search button.

  var load = from queryInfo in db.tblinfos
                    join queryOrder in db.tblorders
                    on queryInfo.ID equals queryOrder.InfoID
where (queryInfo.Firstname == txtSearch.Text) || (queryInfo.Lastname == txtSearch.Text)
select new { queryInfo.Firstname, queryInfo.Lastname, queryOrder.Productname };

            dataGridView1.DataSource = load;

If you want to search record that match any character, instead using ==(equal sign), use Contains or Like keywords. Just like the example given below!

where (queryInfo.Firstname.Contains(txtSearch.Text)) || (queryInfo.Lastname.Contains(txtSearch.Text))

OR

where SqlMethods.Like(queryInfo.Firstname,search) || SqlMethods.Like(queryInfo.Lastname,search)

When using this method don't forget to used namespace using System.Data.Linq.SqlClient;

Note: don't forget to use string search = "%" + txtSearch.Text + "%";

Please visit Language Integrated Query (LINQ) syntax and other documentation to MSDN.

How to use LINQ syntax to query data


Language Integrated Query (LINQ) is possibility the most exciting new feature Microsoft added that first introduced in Visual Studio 2008 and .NET Framework version 3.5.

Language Integrated Query (LINQ) has its own capability in querying a data from database, flexibility and overwhelming reach of LINQ to change the way developers write application. Nevertheless, LINQ is a powerful strongly typed syntax for accessing queries and generating results which improves developer productivity to write less code that create a better application. For more information visit MSDN LINQ.

Actually, when I first explore this language it looks weird and feels none – sense. Indeed, it helps saves a lot of works. So far, I’m still learning about this language and publish it as my own future reference at the same time providing relevant information for those trying to learn LINQ. In this tutorial, it shows how to use queries using LINQ.

Creating simple LINQ Queries using select, from, where, orderby, and join keywords.

First of all, I’ll show you a basic LINQ query and for the next tutorial we’re going to work with databases queries. For now it’s simply a sort of a given array form.

     string[] queryString = { "LINQ", "VB.NET", "C#", "ASP.NET", "C++" };

            var str = from strquery in queryString
                      select strquery;

            foreach (var data in str)
            {
                listBox1.Items.Add(data);      
            }
Output:
LINQ
VB.NET
C#
ASP.NET
C++

In this example it sorts alphabetically with orderby keyword.

     string[] queryString = { "LINQ", "VB.NET", "C#", "ASP.NET", "C++" };

            var str = from strquery in queryString
                      orderby strquery            
                      select strquery;

            foreach (var data in str)
            {
                listBox1.Items.Add(data);      
            }
Output:
ASP.NET
C#
C++
LINQ
VB.NET

In this example it shows only specific result with where keyword.

     string[] queryString = { "LINQ", "VB.NET", "C#", "ASP.NET", "C++" };

            var str = from strquery in queryString
                      where strquery == "LINQ"
                      orderby strquery            
                      select strquery;

            foreach (var data in str)
            {
                listBox1.Items.Add(data);      
            }
Output:
LINQ

In this example it will display a number from 1 to 5

     int[] number = { 1, 2, 3, 4, 5 };

            var num = from querynum in number
                      select querynum;
            foreach (var mynumber in num)
            {
                listBox1.Items.Add(mynumber);
            }
Output:
1
2
3
4
5

In this example use join keyword to join two arrays and display the same element of both arrays.

     int[] num1 = { 1, 2, 3, 4, 5 };
            int[] num2 = { 1, 3, 7, 9, 5 };

            var joinNum = from queryNum1 in num1
                          join queryNum2 in num2
                          on queryNum1 equals queryNum2
                          select new {queryNum1,queryNum2};

            foreach (var myjoin in joinNum)
            {
                listBox1.Items.Add(myjoin);
            }
Output:
{queryNum1 = 1, queryNum2 = 1}
{queryNum1 = 3, queryNum2 = 3}
{queryNum1 = 5, queryNum2 = 5}

When you noticed the output contains three array elements 1, 3, and 5 that compare num1 and num 2 Array. However there’s other way how to construct join statement, instead with join, they use from, here is sample code.

     var fromjoin = from queryA in arrayA
                           from queryB in arrayB
                           where queryA == queryB
                           select new { queryA, queryB };

It will generate the same output as what join statement stated.

If you are newbie using LINQ and didn’t know yet, but it has already background either VB.NET or C#, don’t worry because .NET 3.5+ has a build – in function that supports query syntax. Unfortunately, lower version of .NET doesn’t support LINQ.