Search This Blog

Friday, February 14, 2014

Export SQL table data to a CSV file


 We can use BCP (bulk copy program) for exporting SQL table data to a CSV file.
About BCP :
The bcp utility bulk copies data between an instance of Microsoft SQL Server and a data file in a user-specified format. The bcp utility can be used to import large numbers of new rows into SQL Server tables or to export data out of tables into files. 

Syntax:
bcp [database_name.] schema.{table_name | view_name | "query" {in data_file | out data_file | queryout data_file | format nul}

   [-a packet_size]
   [-b batch_size]
   [-c]
   [-C { ACP | OEM | RAW | code_page } ]
   [-d database_name]
   [-e err_file]
   [-E]
   [-f format_file]
   [-F first_row]
   [-h"hint [,...n]"] 
   [-i input_file]
   [-k]
   [-K application_intent]
   [-L last_row]
   [-m max_errors]
   [-n]
   [-N]
   [-o output_file]
   [-P password]
   [-q]
   [-r row_term]
   [-R]
   [-S [server_name[\instance_name]]
   [-t field_term]
   [-T]
   [-U login_id]
   [-v]
   [-V (80 | 90 | 100 )]
   [-w]
   [-x]
   /?

Example:
  declare @fileName  nvarchar(400)
declare @outputPath nvarchar(400)
declare @query nvarchar(4000)

  declare @dbServer varchar(50)
declare @dbName varchar(50)
declare @dbUser varchar(50)
declare @dbPassword varchar(50)
declare @sql nvarchar(4000)



 set @fileName  ='[FileName]'
set @outputPath = '[OutputPath]' /*Where sql server is installed*/

 set @dbServer ='[Server]'
set @dbName = '[DatabaseName]'
set @dbUser = '[DatabaseUser]'
set @dbPassword = '[DatabasePassword]'

 set @query ="Select * from [TableName]"

 set @sql = N'bcp "' + @query + '" queryout "' + @outputPath + @fileName  + '.csv" -S ' + @dbServer + ' -d ' + @dbName + ' -U ' + @dbUser + ' -P ' + @dbPassword + ' -c -t,'

exec xp_cmdshell @sql

Wednesday, February 12, 2014

HTML 5- Structural Elements

HTML 5- Structural Elements:
  1. <header>
  2. <hgroup>
  3. <footer>
  4. <article>
  5. <section>
  6. <aside>
  7. <nav>


Thursday, October 18, 2012

Move elements from one list to another using jquery

This post will not help the C# gurus. Because they are already using this feature different techniques. But I hope this will be helpful for the PHP beginners :) . Now I am going to show you how you can move list items from one list box to another using simple jquery. Using jquery it is very simple than you think. :)

This is the Jquery portion:

 <script src="jquery-1.6.2.js"></script>

 <script>

 function move_forward()

 {

     //taking the selected items of list 1 and concatenating to a variable named forward_variable.

   var forward_variable='';

   $("#list1 :selected").each(function(){

       forward_variable+="<option value='"+$(this).val()+"'>"+$(this).html()+"</option>";

       $(this).remove();  

   });

     //Now appending the selected firs list's element to the list 2.

   $("#list2").append(forward_variable);

     //Sorting the list 2 so that it shows the list alphabetically

   sort_element("list2");

 }

 function move_backward()

 {

   var backward_variable='';

     //taking the selected items of list 2 and concatenating to a variable named backward_variable.

   $("#list2 :selected").each(function(){

       backward_variable+="<option value='"+$(this).val()+"'>"+$(this).html()+"</option>";

       $(this).remove();  

   });

    //Now appending the selected firs list's element to the list 1.

   $("#list1").append(backward_variable);

     //Sorting the list 2 so that it shows the list alphabetically

   sort_element("list1");

 }

 //Sorting function to sort the elements

 function sort_element(id)

 {

   var select_element = $('#'+id);

   var options_element = select_element.children('option').get();

   options_element.sort(function(a, b) {

     var compA = $(a).text().toUpperCase();

     var compB = $(b).text().toUpperCase();

     return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;

   })

   $.each(options_element, function(index, items) { select_element.append(items); });

 }

 </script>


Now comes the html portion.
 <select multiple="multiple" name="list1" id="list1" style="width:200px">

   <option value="1">Ecstasy</option>  

   <option value="2">Tanjim</option>

   <option value="3">Rex</option>

   <option value="4">Artisti</option>

   <option value="5">Infinity</option>

 </select>

 <input type="button" name="forward" id="forward" onclick="move_forward()" value=">>"/>

 <input type="button" name="backward" id="backward" onclick="move_backward()" value="<<"/>

 <select multiple="multiple" name="list2" id="list2" style="width:200px">

 </select>



Simple is not it? Copy and paste the code. Run..

Tuesday, October 16, 2012

ASP.NET Interview Questions - Part 1




1.       Normally the ASP.NET interviewer starts with.....

2.       What’ is the sequence in which ASP.NET events are processed?

3.       In which event are the controls fully loaded?

4.       How can we identify that the Page is Post Back?

5.       How does ASP.NET maintain state in between subsequent request?

6.       What is event bubbling?

7.       How do we assign page specific attributes?

8.       How do we ensure viewstate is not tampered?

9.       What is the use of @ Register directives?

10.   What is the use of Smart Navigation property?

11.   What is AppSetting Section in “Web.Config” file?

12.   Where is View State information stored?

13.   What is the use of @ Output Cache directive in ASP.NET?

14.   How can we create custom controls in ASP.NET?

15.   How many types of validation controls are provided by ASP.NET?

16.   Can you explain “AutoPostBack”?

17.   How can you enable automatic paging in Data Grid?

18.   What is the use of “GLOBAL.ASAX” file?

19.   What is the difference between “Web.config” and “Machine.Config”?

20.   What is a SESSION and APPLICATION object?

21.   What is the difference between ‘Server.Transfer’ and ‘response. Redirect’ ?

22.   What is the difference between Authentication and authorization?

23.   What is impersonation in ASP.NET?

24.   Can you explain in brief how the ASP.NET authentication process works?

25.   What are the various ways of authentication techniques in ASP.NET?

26.   How does authorization work in ASP.NET?

27.   What is difference between Data grid, Datalist, and repeater?

28.   From performance point of view, how do they rate?

29.   What is the method to customize columns in Data Grid?

30.   How can we format data inside Data Grid?

31.   How to decide on the design consideration to take a Data grid, data list, or repeater?



Sunday, September 30, 2012

How to get an element whose id starts with a particular pattern

Picking an element using its id is very in jquery, is not it? But what if the situation is you have three text fields and every of their id starts with a particular pattern? For example suppose you are working with three text fields

 <input type='text' name='properties_value' id ='properties_value_1' />  
 <input type='text' name='properties_value' id ='properties_value_2' />  
 <input type='text' name='properties_value' id ='properties_value_3' />  
 <input type='button' onclick='take_all_the_input();' value='Show'/>  

Now you want to work on the every text fields value using their id's. What will do? are u planning to write code for each and every text fields like the below???

 <script>  
 function take_all_the_input()  
 {  
    var input1 = $("#properties_value_1").val();  
    var input2 = $("#properties_value_2").val();  
    var input3 = $("#properties_value_3").val();  
   // I assume you just want to alert the values  
   alert(input1+' ' +input2+' '+input3);  
 }//end of function  
 </script>  
The above code will work but that is a very novice approach and will not work if you do not know exactly how many text fields will be there. That means if you have generate the text fields dynamically in that case you cant fix the number of text fields. Now come to the solution. The better solution (I am not telling it best but better because after reading this post you may write in your blog even better solution than my solution :) ). So the better solution is go through every text field's id that starts with a particular pattern (in this case 'properties_value_') since every id has started with 'properties_value_' and work on those values.

The code will be
 <script>  
 function take_all_the_input()  
 {  
   $("input[id^='properties_value_']").each(function()  
    {  
     // I assume you just want to alert the values  
     alert($(this).val());  
    }  
 }//end of function  
 </script>  

See we have used $("input[id^='properties_value_']").each(function() {..... Here you are going to traverse each of the id that starts with 'properties_value_' How are taking the id that starts with a particular pattern? using ^= . So this will give the attributes that starts with some pattern... On the other hand the $= will help you to find the ids that ends with a particular pattern.

Hope this helps.. Happy coding.


Monday, September 24, 2012

Upgrage yourself, dont rely on what you are

You are developing your career where upgrading yourself is must. Do not just rely on PHP or .NET or Android or whatever. May be you are a very good PHP coder.  Knows so many  things but you don't know everything. But I know you will not be able to know everything. But You must have to have the eagerness to learn new things. Suppose you are very good in PHP 4. But now PHP 6 is going to reign the PHP world but still you do not want to learn even PHP 5 and as a result you are not doing OOP  just because upto PHP 4 OOP was not used that much!!! Then sorry. This is not your field. Suppose you are an advanced developer. Going to develop a chat script. But you dont have the guts to study on node.js instead you are finding a shortcut way to do it using database!!! sorry again. So just keep in mind only PHP will give nothing until you upgrade yourself.  Today you are writing duplicate codes but you are continuing it projects after projects. You should not do this. You have to have the eagerness to follow the DRY (Do not Repeat Yourself) approach. Try to attach with online group, discussion, visit popular blogs or magazines to upgrade. Now it is the time to make rounded corner using CSS3 so please dont try to do it using photoshop to make a rounded corner image.


Tuesday, September 18, 2012

Populate drop down list with XML in C#

Create XML File  named CollectionModeinSales.xml in root folder:

<?xml version="1.0" encoding="utf-8" ?>
<CollectionModes>
  <CollectionMode>
    <text>Cash</text>
    <value>Cash</value>
 
</CollectionMode>
  <CollectionMode>
    <text>Cheque</text>
    <value>Cheque</value>
  </CollectionMode>

  <CollectionMode>
    <text>D.D</text>
    <value>D.D</value>
  </CollectionMode>

  <CollectionMode>
    <text>TT</text>
    <value>TT</value>
  </CollectionMode>

  <CollectionMode>
    <text>Credit</text>
    <value>Credit</value>
  </CollectionMode>

</CollectionModes>





Add asp:DropDownList in ASPX file

 <asp:DropDownList ID="ddlCollectionType" runat="server" Width="106px">
                                                                   </asp:DropDownList>

C# Code behind file:

            DataSet dsCollectionType = new DataSet();
           
    dsCollectionType.ReadXml(AppDomain.CurrentDomain.BaseDirectory + "CollectionModeinSales.xml");
    ddlCollectionType.DataSource = dsCollectionType.Tables[0];
    ddlCollectionType.DataTextField = "text";
    ddlCollectionType.DataValueField ="value";
    ddlCollectionType.DataBind();