Sunday, December 30, 2012

Read XML and convert to dataset


Let's the path of XML file is C:\hello.xml


string strXmlPath="C:\hello.xml";
 DataSet ds = new DataSet();
        ds.ReadXml(strXmlPath);
        return ds.Tables[0];

above method will return table[0] of ds

Sybase command to connect to database


Command to connect:

isql -U user -P password -i script_name.sql -o log_name.log

User 
The owner of the database. To run admin scripts, the user is the sa user. The admin script creates the database owner for the repository. When you run the schema scripts, the user must be the database owner.

Password 
The password for the sa user.

script_name
The name of the script.

log_name 
The name of the log file.

How to access Oracle from C++

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/oci/oci.htm

Regular Expression in ASP.Net


RegularExpressionValidator for Email ID: 

Here I have shown a textbox with ID="txtEmail". Regular Expression validator for Email ID:

 
                                    ValidationGroup="vgSubmit" ForeColor="Red">
                                    ValidationGroup="vgSubmit" ControlToValidate="txtEmail" CssClass="requiredFieldValidateStyle"
                    ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">




RegularExpressionValidator for U.S. Phone Number:


 (000-000-0000)
                                    ValidationGroup="vgSubmit" ForeColor="Red">
                                    ValidationGroup="vgSubmit" ControlToValidate="txtPhoneNumber" ForeColor="Red"
                    ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">


SQL Loader in Oracle

basic sql loader comments----
load data
 infile 'c:\data\mydata.csv'
 into table emp
 fields terminated by "," optionally enclosed by '"'    
 ( empno, empname, sal, deptno )

Loading delimited (variable length) data
In the first example we will show how delimited (variable length) data can be loaded into Oracle:
LOAD DATA
 INFILE *
 INTO TABLE load_delimited_data
 FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
 TRAILING NULLCOLS
 (  data1,
    data2
 )
BEGINDATA
11111,AAAAAAAAAA
22222,"A,B,C,D,"
NOTE: The default data type in SQL*Loader is CHAR(255). To load character fields longer than 255 characters, code the type and length in your control file. By doing this, Oracle will allocate a big enough buffer to hold the entire column, thus eliminating potential "Field in data file exceeds maximum length" errors. Example:
...
resume char(4000),
...
Loading positional (fixed length) data
If you need to load positional data (fixed length), look at the following control file example:
LOAD DATA
  INFILE *
  INTO TABLE load_positional_data
  (  data1 POSITION(1:5),
     data2 POSITION(6:15)
  )
BEGINDATA
11111AAAAAAAAAA
22222BBBBBBBBBB
For example, position(01:05) will give the 1st to the 5th character (11111 and 22222).

Can one modify data as the database gets loaded?

Data can be modified as it loads into the Oracle Database. One can also populate columns with static or derived values. However, this only applies for the conventional load path (and not for direct path loads). Here are some examples:
LOAD DATA
  INFILE *
  INTO TABLE modified_data
  (  rec_no                      "my_db_sequence.nextval",
     region                      CONSTANT '31',
     time_loaded                 "to_char(SYSDATE, 'HH24:MI')",
     data1        POSITION(1:5)  ":data1/100",
     data2        POSITION(6:15) "upper(:data2)",
     data3        POSITION(16:22)"to_date(:data3, 'YYMMDD')"
  )
BEGINDATA
11111AAAAAAAAAA991201
22222BBBBBBBBBB990112
LOAD DATA
  INFILE 'mail_orders.txt'
  BADFILE 'bad_orders.txt'
  APPEND
  INTO TABLE mailing_list
  FIELDS TERMINATED BY ","
  (  addr,
     city,
     state,
     zipcode,
     mailing_addr   "decode(:mailing_addr, null, :addr, :mailing_addr)",
     mailing_city   "decode(:mailing_city, null, :city, :mailing_city)",
     mailing_state,
     move_date      "substr(:move_date, 3, 2) || substr(:move_date, 7, 2)"
  )

[edit]Can one load data from multiple files/ into multiple tables at once?

Loading from multiple input files
One can load from multiple input files provided they use the same record format by repeating the INFILE clause. Here is an example:
LOAD DATA
  INFILE file1.dat
  INFILE file2.dat
  INFILE file3.dat
  APPEND
  INTO TABLE emp
  ( empno  POSITION(1:4)   INTEGER EXTERNAL,
    ename  POSITION(6:15)  CHAR,
    deptno POSITION(17:18) CHAR,
    mgr    POSITION(20:23) INTEGER EXTERNAL
  )
Loading into multiple tables
One can also specify multiple "INTO TABLE" clauses in the SQL*Loader control file to load into multiple tables. Look at the following example:
LOAD DATA
 INFILE *
 INTO TABLE tab1 WHEN tab = 'tab1'
   ( tab  FILLER CHAR(4),
     col1 INTEGER
   )
 INTO TABLE tab2 WHEN tab = 'tab2'
   ( tab  FILLER POSITION(1:4),
     col1 INTEGER
   )
BEGINDATA
tab1|1
tab1|2
tab2|2
tab3|3
The "tab" field is marked as a FILLER as we don't want to load it.
Note the use of "POSITION" on the second routing value (tab = 'tab2'). By default field scanning doesn't start over from the beginning of the record for new INTO TABLE clauses. Instead, scanning continues where it left off. POSITION is needed to reset the pointer to the beginning of the record again. In delimited formats, use "POSITION(1)" after the first column to reset the pointer.
Another example:
LOAD DATA
 INFILE 'mydata.dat'
 REPLACE
 INTO TABLE emp
      WHEN empno != ' '
 ( empno  POSITION(1:4)   INTEGER EXTERNAL,
   ename  POSITION(6:15)  CHAR,
   deptno POSITION(17:18) CHAR,
   mgr    POSITION(20:23) INTEGER EXTERNAL
 )
 INTO TABLE proj
      WHEN projno != ' '
 (  projno POSITION(25:27) INTEGER EXTERNAL,
    empno  POSITION(1:4)   INTEGER EXTERNAL
 )

[edit]Can one selectively load only the records that one needs?

Look at this example, (01) is the first character, (30:37) are characters 30 to 37:
LOAD DATA
  INFILE  'mydata.dat' BADFILE  'mydata.bad' DISCARDFILE 'mydata.dis'
  APPEND
  INTO TABLE my_selective_table
  WHEN (01) <> 'H' and (01) <> 'T' and (30:37) = '20031217'
  (
     region              CONSTANT '31',
     service_key         POSITION(01:11)   INTEGER EXTERNAL,
     call_b_no           POSITION(12:29)   CHAR
  )
NOTE: SQL*Loader does not allow the use of OR in the WHEN clause. You can only use AND as in the example above! To workaround this problem, code multiple "INTO TABLE ... WHEN" clauses. Here is an example:
LOAD DATA
  INFILE  'mydata.dat' BADFILE  'mydata.bad' DISCARDFILE 'mydata.dis'
  APPEND
  INTO TABLE my_selective_table
  WHEN (01) <> 'H' and (01) <> 'T'
  (
     region              CONSTANT '31',
     service_key         POSITION(01:11)   INTEGER EXTERNAL,
     call_b_no           POSITION(12:29)   CHAR
  )
  INTO TABLE my_selective_table
  WHEN (30:37) = '20031217'
  (
     region              CONSTANT '31',
     service_key         POSITION(01:11)   INTEGER EXTERNAL,
     call_b_no           POSITION(12:29)   CHAR
  )

[edit]Can one skip certain columns while loading data?

One cannot use POSITION(x:y) with delimited data. Luckily, from Oracle 8i one can specify FILLER columns. FILLER columns are used to skip columns/fields in the load file, ignoring fields that one does not want. Look at this example:
LOAD DATA
TRUNCATE INTO TABLE T1
FIELDS TERMINATED BY ','
( field1,
  field2 FILLER,
  field3
)
BOUNDFILLER (available with Oracle 9i and above) can be used if the skipped column's value will be required later again. Here is an example:
LOAD DATA
INFILE *
TRUNCATE INTO TABLE sometable
FIELDS TERMINATED BY ","  trailing nullcols
(
 c1,
 field2 BOUNDFILLER,
 field3 BOUNDFILLER,
 field4 BOUNDFILLER,
 field5 BOUNDFILLER,
 c2     ":field2 || :field3",
 c3     ":field4 + :field5"
)

[edit]How does one load multi-line records?

One can create one logical record from multiple physical records using one of the following two clauses:
  • CONCATENATE - use when SQL*Loader should combine the same number of physical recordstogether to form one logical record.
  • CONTINUEIF - use if a condition indicates that multiple records should be treated as one. Eg. by having a '#' character in column 1.

[edit]How does one load records with multi-line fields?

Using Stream Record format, you can define a record delimiter, so that you're allowed to have the default delimiter ('\n') in the field's content.
After the INFILE clause set the delimiter:
 load data
 infile "test.dat" "str '|\n'"
 into test_table
 fields terminated by ';' TRAILING NULLCOLS
 (
   desc,
   txt
 )
test.dat:
 one line;hello dear world;|
 two lines;Dear world,
 hello!;|
Note that this doesn't seem to work with inline data (INFILE * and BEGINDATA).

google maps in asp.net


var map;
function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
        zoom: 8,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map"), myOptions);
    var marker = new google.maps.Marker
    (
        {
            position: new google.maps.LatLng(-34.397, 150.644),
            map: map,
            title: 'Click me'
        }
    );
    var infowindow = new google.maps.InfoWindow({
        content: 'Location info:
Country Name:
LatLng:'
    });
    google.maps.event.addListener(marker, 'click', function () {
        // Calling the open method of the infoWindow 
        infowindow.open(map, marker);
    });
}
window.onload = initialize;

Wednesday, March 21, 2012

How to Access SQL Server from C++

Accessing SQL Server from C++

#define DBNTWIN32
#include
#include
#include
#include

// Forward declarations of the error handler and message handler.

int err_handler(PDBPROCESS, INT, INT, INT, LPCSTR, LPCSTR);
int msg_handler(PDBPROCESS, DBINT, INT, INT, LPCSTR, LPCSTR,
LPCSTR, DBUSMALLINT);
main()
{
   PDBPROCESS dbproc; // The connection with SQL Server.
   PLOGINREC login; // The login information.
   DBCHAR name[100];
   DBCHAR city[100];

// Install user-supplied error- and message-handling functions.

   dberrhandle (err_handler);
   dbmsghandle (msg_handler);

// Initialize DB-Library.

   dbinit ();

// Get a LOGINREC.

   login = dblogin ();
   DBSETLUSER (login, "my_login");
   DBSETLPWD (login, "my_password");
   DBSETLAPP (login, "example");

// Get a DBPROCESS structure for communication with SQL Server.

   dbproc = dbopen (login, "my_server");

// Retrieve some columns from the authors table in the
// pubs database.
// First, put the command into the command buffer.

   dbcmd (dbproc, "SELECT au_lname, city FROM pubs..authors");
   dbcmd (dbproc, " WHERE state = 'CA' ");

// Send the command to SQL Server and start execution.

   dbsqlexec (dbproc);

// Process the results.

   if (dbresults (dbproc) == SUCCEED)
   {

// Bind column to program variables.

      dbbind (dbproc, 1, NTBSTRINGBIND, 0, name);
      dbbind (dbproc, 2, NTBSTRINGBIND, 0, city);

// Retrieve and print the result rows.

      while (dbnextrow (dbproc) != NO_MORE_ROWS)
      {
         printf ("%s from %s\n", name, city);
      }
   }

// Close the connection to SQL Server.

   dbexit ();
   return (0);
}

int err_handler (PDBPROCESS dbproc, INT severity,
INT dberr, INT oserr, LPCSTR dberrstr, LPCSTR oserrstr)
{
   printf ("DB-Library Error %i: %s\n", dberr, dberrstr);
   if (oserr != DBNOERR)
   {
      printf ("Operating System Error %i: %s\n", oserr, oserrstr);
   }
   return (INT_CANCEL);
}

int msg_handler (PDBPROCESS dbproc, DBINT msgno, INT msgstate,
INT severity, LPCSTR msgtext, LPCSTR server,
LPCSTR procedure, DBUSMALLINT line)
{
   printf ("SQL Server Message %ld: %s\n", msgno, msgtext);
   return (0);
}

Saturday, February 18, 2012

bangladesh government

bangladesh government website: http://www.bangladesh.gov.bd/
local government : www.lged.gov.bd/
bangladesh power development board: www.bpdb.gov.bd/
prothom alo: eprothom-alo.com
 

Sunday, January 29, 2012

how to add dynamic rows in asp.net gridview control

To get started, let’s grab a GridView control from the Visual Studio Toolbox and put it in the WebForm. The mark up would look something like this:

<asp:gridview ID="Gridview1" runat="server" ShowFooter="true"
                             AutoGenerateColumns="false">
        <Columns>
        <asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
        <asp:TemplateField HeaderText="Header 1">
            <ItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server">asp:TextBox>
            ItemTemplate>
        asp:TemplateField>
        <asp:TemplateField HeaderText="Header 2">
            <ItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server">asp:TextBox>
            ItemTemplate>
        asp:TemplateField>
        <asp:TemplateField HeaderText="Header 3">
            <ItemTemplate>
                 <asp:TextBox ID="TextBox3" runat="server">asp:TextBox>
            ItemTemplate>
            <FooterStyle HorizontalAlign="Right" />
            <FooterTemplate>
                 <asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" />
            FooterTemplate>
        asp:TemplateField>
        Columns>
asp:gridview>

Here’s the code block below:


private void SetInitialRow(){

        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
        dt.Columns.Add(new DataColumn("Column1", typeof(string)));
        dt.Columns.Add(new DataColumn("Column2", typeof(string)));
        dt.Columns.Add(new DataColumn("Column3", typeof(string)));
        
        dr = dt.NewRow();
        dr["RowNumber"] = 1;
        dr["Column1"] = string.Empty;
        dr["Column2"] = string.Empty;
        dr["Column3"] = string.Empty;
        dt.Rows.Add(dr);

        //Store the DataTable in ViewState
        ViewState["CurrentTable"] = dt;

        Gridview1.DataSource = dt;
        Gridview1.DataBind();
}
 
Now lets call the method above in Page_Load event:
 
protected void Page_Load(object sender, EventArgs e){
        if (!Page.IsPostBack){
            SetInitialRow();  
        }
}
Now let’s create the method for generating the rows when clicking the Button. Here are the code blocks below:
 
 
private void AddNewRowToGrid(){

        int rowIndex =0;
        if (ViewState["CurrentTable"] != null)
        {
            DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
            DataRow drCurrentRow = null;
            if (dtCurrentTable.Rows.Count > 0)
            {
                for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                {
                    //extract the TextBox values
                    TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
                    TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
                    TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");

                    drCurrentRow = dtCurrentTable.NewRow();
                    drCurrentRow["RowNumber"] = i + 1; 
                    drCurrentRow["Column1"] = box1.Text;
                    drCurrentRow["Column2"] = box2.Text;
                    drCurrentRow["Column3"] = box3.Text;

                    rowIndex++;
                }

                //add new row to DataTable
                dtCurrentTable.Rows.Add(drCurrentRow);
                //Store the current data to ViewState
                ViewState["CurrentTable"] = dtCurrentTable;

                //Rebind the Grid with the current data
                Gridview1.DataSource = dtCurrentTable;
                Gridview1.DataBind();
           }
        }
        else
        {
            Response.Write("ViewState is null");
        }

        //Set Previous Data on Postbacks
        SetPreviousData();
}
 
You will also noticed that we call the method SetPreviousData() at the bottom part of the codes above. Now where is that method?  Below are the code blocks for that method:

private void SetPreviousData(){

        int rowIndex = 0;
        if (ViewState["CurrentTable"] != null)
        {
            DataTable dt = (DataTable)ViewState["CurrentTable"];
            if (dt.Rows.Count > 0)
            {
                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
                    TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
                    TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");

 
                    box1.Text = dt.Rows[i]["Column1"].ToString();
                    box2.Text = dt.Rows[i]["Column2"].ToString();
                    box3.Text = dt.Rows[i]["Column3"].ToString();
                   
                    rowIndex++;

                }
            }
        }
}
 
 
Now, since the methods are all set then we can call this at Button Click event of the Button.

protected void ButtonAdd_Click(object sender, EventArgs e){ AddNewRowToGrid(); }
 
   

how to open telnet connection

    SocketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    String szIPSelected = txtIPAddress.Text;
    String szPort = txtPort.Text;
    int alPort = System.Convert.ToInt16(szPort, 10);

    System.Net.IPAddress remoteIPAddress = System.Net.IPAddress.Parse(szIPSelected);
    System.Net.IPEndPoint remoteEndPoint = new System.Net.IPEndPoint(remoteIPAddress, alPort);
    SocketClient.Connect(remoteEndPoint);

how to connect to sql server two database at a time

you can connect sql sever two database at a time within one connection establish...

please use
"ServerName.dbo.DatabaseName" when you select, insert,update, delete table for connect any other server within single connection establish.

like ...

you are connected to MASTER server but from this connection you want to open an table which is currently under in "STUDENT" database, then use following way

select * from STUDENT.dbo.result;

how to search in solaris directory

lot's of way you can find in internet for searching directory, file in solaris, unix or linux. below is the another way to deal the issues.....

example for find command:

find . -print | grep -i "pattern"
find . -type f -print | grep -i "filename" # match files only
find . -type f -print | grep -i "*.c"
find . -type f -print | grep -i "foo.c"
find . -type d -print | grep -i "dirname" # match dirs only
find . -type d -print | grep -i "directory-name"


grep command example:


grep 'word' filename grep 'string1 string2'  filename cat otherfile | grep 'something' command | grep 'something' command option1 | grep 'data' grep --color 'data' fileName


if anythings more you need please mail me