Sunday 21 April 2013

How to remove / hide index.php from url in yii framework (PHP)

  • remove index.php from url in yii hide index.php from url in yii php url styling php
Just follow steps:

  • Make sure that the hosting / your pc mod_rewrite module is active. if not actively try to activate in a way, open the httpd.conf file. You can check this in the phpinfo.php to find out.
Find line #LoadModule rewrite_module modules/mod_rewrite.so
and remove just '#'

  • Create file .htaccess under directory protected/ or protected/www/ where app's index.php file is hosted and add following code snippet
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

  • Set main.php in your yii configuration, at component :
'urlManager' => array(
                'urlFormat'=>'path',
                'showScriptName'=>false,
                'caseSensitive'=>false,        
               ),

  • Now just hits the your app Url.

Database connection using JDBC ODBC Driver in JAVA

  • java database connection jdbc odbc how to connect java to database database connectivity simple code for java database connectivity

Code Snippet :


import java.sql.*;

class insertIntoTable

{
 public static void main(String args[]) {
       try {

           //load database driver
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
           
           //connect To database
          Connection c;
          c=DriverManager.getConnection("jdbc:odbc:RS");
          System.out.println("connect To database");  
  
           //create Statement
          Statement s;
          s=c.createStatement();
        
          //create String
         String x;
         x="INSERT into RS Values ('Shiva','Aiwale','Vita',21)";
   
          //execute query
         s.executeUpdate(x);
         System.out.println("Data Successfully Inserted");     
         c.close();
      }

      catch(Exception e) 
{
         System.out.println("Exception ="+e.getMessage());
      } 

  }

}

Saturday 20 April 2013

Steps To Display Database Content to DataGridView in C#

  • .net asp .net how to use data grid view dynamic data in data grid view how to implement datagridview

1)  Establish connection to database :

SqlConnection conObj =  new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=F:\WindowsFormsApplication5\WindowsFormsApplication5\StudentDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");

Note : 
  • SqlConnection Class found in "System.Data.SqlClient" Namespace, So that you need to specify ( using System.Data.SqlClient; ) namespace
         
2) Create string based on what data need to Display :

        String selectString="SELECT  * FROM employee";

3) Execute above string :


SqlDataAdapter    dataAdapterObj = new SqlDataAdapter(selectString, conObj);

Note : 
  • SqlDataAdapter constructor execute selectString and store result in dataAdapterObj
  • Require two input selectstring to execute and connection object (conObj)

4)Attach data from dataAdapterObject to DataTable object :

        DataAdapter dtObj=new DataAdapter();
                   dtObj.fill(dataAdapterObj );

5)Finally Attach data from data table (dtObj) to DataGridView using DataSource Property :

        datagridview1.DataSource=dtObj;

I hope you got it... If you have any query then ask me...


SAMPLE :