Wednesday, November 20, 2013

Basic difference between .net 3.5 and 4.0

In this article I will explain difference between .net 3.5 and 4.0.


Difference between Framework 3.5 and Framework 4.0:

  1. EnableViewState - [true or false] in Framework 3.5
    EnableViewState -[Enabled/Disabled/Inherits] in Framework 4.0.


    2.Keyword and Description is added in Framework 4.0 while it is not available in Framework 3.5 in the Page Directives.

    3.use Multi-Targeting Feature:
    For using multi-targeting feature , users will have to add “targetframework” attribute in the compilation element of the web.config file. 


    Dear all i knew only this difference if some one know more pls welcome to add here   

Monday, November 18, 2013

String or binary data would be truncated. The statement has been terminated in .net

Introduction:

how to solve the problem of “string or binary data would be truncated. The statement has been terminated". When data Insert in sql server.

 Description:


  In one project I am trying to insert data into one table using SQL queries at that time I got error like “String or binary data would be truncated. The statement has been terminated.” Actually this problem because of I declared column datatype varchar(200) but I am inserting data more than 200+ characters in that column. To solve this problem I modified column datatype varcha (200) to varchar(MAX)

I will explain with one example I have query like this
DECLARE @Details TABLE(UserId INT, Note VARCHAR(MAX))
INSERT INTO @UserDetails(UserId,UserName)
VALUES(1,'Arjun Walmiki','')
SELECT * FROM @Details
If you observe above query I declared Note field with VARCHAR(200) and inserting more than 200 characters because of that I got error like 


 



Note:- Welcome to add your comment and suggestion. 

Wednesday, November 6, 2013

Remove the commas remove the bracket in Java

In this program you will learn Remove the commas and bracket We are going to use replaceAll() or replace() method of String class in Java. The description of the code is given below for the usage of the method.

Description of the code:-

Here, you will get to know about the replaceAll() or replace() method through the following java program. In the program code given below, we have taken a String Or list.

String name=String.valueOf(loginCountBean1.getM_strEmployeeName());
hssfCell1.setCellValue(name);
// you can use below line of code for replace the commas.
 
hssfCell1.setCellValue(name.replaceAll("\'", "")); 

 Using List :-

String data = String.valueOf(cells.next());

HSSFCell hssfCell = hssfHeader.createCell(x);

hssfCell.setCellValue(data);

 // you can use below line of code for replace the bracket  from List.

hssfCell.setCellValue(data.replace("[", "").replaceAll("]", "")); 



Note :- I am use here Excel sheet to display the result from Mysql server.


Thank you to read and welcome to add your suggestion .
 

Thursday, October 24, 2013

String to Integer Conversion in Java

here are different ways of converting String object into Integer in Java :
1) By using Intger.parseInt(String string-to-be-converted) method
This is my preferred way of converting it, Extremely easy and most flexible way of converting String to Integer. Let see an example of String to int conversion:

 //using Integer.parseInt
        int i = Integer.parseInt("123");
        System.out.println("i: " + i);

Integer.parseInt() method will throw NumberFormatException if String provided is not a proper number. Same technique can be used to convert other data type like float and Double to String in Java. Java API provides static methods like Float.parseFloat() and Double.parseDouble() to perform data type conversion.
2) There is another way of converting String into Integer which was hidden to me for long time mostly because I was satisfied with Integer.parseInt() method. This is an example of Factory method design pattern in Java and known as Integer.valueOf(), this is also a static method like main and can be used as utility for string to int conversion. Let’s see an example of using Integer.valueOf() to convert String into int in java.

//How to convert numeric string = "000000081" into Integer value = 81
int i = Integer.parseInt("000000081");
System.out.println("i: " + i);

It will ignore the leading zeros and convert the string into int. This method also throws NumberFormatException if string provided does not represent actual number. Another interesting point about static valueOf() method is that it is used to create instance of wrapper class during Autoboxing in Java and can cause subtle issues while comparing primitive to Object e.g. int to Integer using equality operator (==),  because caches Integer instance in the range -128 to 127.

Tuesday, October 1, 2013

Jar file Error In Java

Dear Friend this post to those people those are start learning java.When people are new in error so worry about this common error the error as below

java.io.IOException: Unexpected end of input stream
        at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:339)
        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:782)
        at com.mysql.jdbc.Connection.createNewIO(Connection.java:1585)
        at com.mysql.jdbc.Connection.<init>(Connection.java:524)
        at com.mysql.jdbc.Driver.connect(Driver.java:359)
        at java.sql.DriverManager.getConnection(DriverManager.java:512)
        at java.sql.DriverManager.getConnection(DriverManager.java:140)
        at com.aquafold.aquacore.scripts.ConnectionProperties.getConnection(Unknown Source)
        at com.aquafold.datastudio.mainframe.dialog.ConnectionDialog.onOk(Unknown Source)
        at com.aquafold.datastudio.mainframe.dialog.ConnectionDialog.access$600(Unknown Source)
 
 
 Solution for this error:-
 
( Your JVM is picking up an old version of Connector/J somewhere in it's classpath.)
 
Means you are add old version of my(e.g mysql-connector-java-5.1.18-bin.jar) 
 So you add latest version of jar fine than problem was solved.
 
 
thanks you for read welcome to add you suggestion.  
 
 
 
 
 

Tuesday, September 24, 2013

Server Error in IIS APPPOOL\DefaultAppPool

My self  face problem for hosting the web service from my local system .
So i finally decided to put this in my blog along with screen shots for easy understanding purpose.

Problem: The error as below:-
 







Solution:
The reason why you are seeing this screen is .. When browser requests a page, request goes the IIS (Internet  Information Services). If  the request needs some data from the SQL server IIS tries to access the SQL server With this Access name which dont have credentials to access that particular database. To Resolve this you have to give the permissions for the user to that particular database as follows.

Step1:

Start-Type-iis the below screen show -click on Internet Information Services(IIS) Manager.
 
Step2:

when u click on Internet Information Services(IIS) Manager. the scr as below

Next scr when see option :-

Click on Application pool scn short as below 

If you see in the above scrn shot i am already short the error to change the ApplicationPoolIdentity to LocalSystem .

 How to change the 

ApplicationPoolIdentity to LocalSystem .

defaultAppPool click on advance setting  (on right hand side u able to see)

the scn as below

 

change the ApplicationPoolIdentity to LocalSystem (i am already done it ..........know problem solve)


Thank you to read my blog ......welcome to share you knowledge ..........See you soon.



Saturday, September 21, 2013

How to read MS Excel file and display into GridView


Dear All
 Today  i am explain you How to read MS Excel file and display into GridView 













Step 1) open-Microsoft office Excel  and put same data inside it and save it any name as u line( i am use arjun.xls file name.The eg as an above)



Step 2) File-New-Projcet-Web-ASP.Net Web Application(Name as per your choice)

Note:-know time to VS u can use any version of VS for it( I am use vs 2008)

 Step 3)  Drop Gridview from toolbox in default.aspx page and Set AutoGenerateColums="false" in the Gridview property.


Step 4)  Edit the column in the Gridview(HeaderText-Address or DataFied =Address(as per excel))



Step 5)Go to default.aspx.cs add namespace (using System.Data; using System.Configuration;
using System.Data.OleDb;)


write a code in  Page_Load



the code are as below 


web.config code :-

<appSettings>
        <add key="Excel2003OleDBConnection" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; Extended Properties=&quot;Excel 8.0;HDR=YES;IMEX=1&quot;"/>
        <add key="Excel2007OleDBConnection" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=&quot;Excel 12.0 Xml;HDR=YES;IMEX=1&quot;"/>
    </appSettings>









default.aspx.cs Code :-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.OleDb;

namespace exceltogridview
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                        string file = Server.MapPath("~/App_Data/arjun.xls");
            string connStr =
                string.Format(ConfigurationManager.AppSettings["Excel2003OleDBConnection"], file);
            DataTable table = new DataTable();
            using (OleDbConnection conn = new OleDbConnection(connStr))
            {
                string sheet = @"SELECT * FROM [sheet1$]";// to avoid error write the sheet name in square bracket

                using (OleDbCommand cmd = new OleDbCommand(sheet, conn))
                {
                    conn.Open();
                    using (OleDbDataAdapter ad = new OleDbDataAdapter(cmd))
                    {
                        ad.Fill(table);
                    }
                    conn.Close();

                };
           
            }
            GridView1.DataSource = table;
            GridView1.DataBind();
            // to loop through the rows use foreach loop

            foreach (DataRow row in table.Rows)
            {

                string firstName = row["FirstName"].ToString();

            }
        }
    }
}



(Please Note :-see this path
"~/App_Data/arjun.xls"
i was keep my xls file in App_Data folder u can found this folder when u click on Solution Explorer )

Know time to come see output Press F5 
out are as blow




Welcome to add your contents and source code to this article