Thursday, March 26, 2009

Find Null or Empty string c# asp.net


Old Method:
if(null != id && 0 != id.length)
{

}

New:-
if(!String.IsNullOrEmpty(id))
{

}

Amazon Webservice C# asp.net Live sample to get product Details all attibutes

Amazon Webservice C# asp.net Live sample to get node Item
 
using
System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

using

System.Xml;

public

partial class tstamz : System.Web.UI.Page

{

string SalesRankOut;

protected void Page_Load(object sender, EventArgs e)

{

getItemDetails();

}

void getItemDetails()

{

//ItemnoCnt = Itemno;

XmlDocument doc = new XmlDocument();

doc.Load(

"http://xml-us.amznxslt.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=16ND0GSSVYMWG9M8ECG2&Operation=ItemLookup&IdType=ASIN&AssociateTag=wwwvislicom-20&ResponseGroup=Large,Offers&ItemId=B0018OKX68");

XmlNodeList lstIsValid = doc.GetElementsByTagName("IsValid");

if (lstIsValid.Count > 0 && lstIsValid[0].InnerXml == "True")

{

XmlNodeList lstItems = doc.GetElementsByTagName("Item");

if (lstItems.Count > 0)

{

XmlNode nItem = lstItems[0];

foreach (XmlNode nChild in nItem.ChildNodes)

{

if (nChild.Name == "DetailPageURL") //string compare !

{

String strURL = nChild.InnerXml; //our data !

}

else if (nChild.Name == "LargeImage")

{

foreach (XmlNode nURLImg in nChild.ChildNodes)

{

if (nURLImg.Name == "URL")

{

string strImage = nChild.InnerXml; //our data !

Response.Write(nChild.FirstChild.InnerText);

Label1.Text =

"<img src=" + nChild.FirstChild.InnerText + "></img>";

// Response.Write("<br>");

//Response.Write(nChild.LastChild.InnerText);

}

}

}

else if (nChild.Name == "ItemAttributes")

{

foreach (XmlNode nIA in nChild.ChildNodes)

{

//Look through each "ItemAttributes" to find the one

//we want again

if (nIA.Name == "Title")

{

String strTitle = nIA.InnerXml; //our data !

Response.Write(

"<li>Title:--- " + strTitle + "</li> ");

}

if (nIA.Name == "Feature")

{

String strFeature = nIA.InnerXml; //our data !

Response.Write(

"<li> " + strFeature + "</li> ");

}

}

}

else if (nChild.Name == "OfferSummary")

{

foreach (XmlNode nOS in nChild.ChildNodes)

{

//looking again

if (nOS.Name == "LowestNewPrice")

{

foreach (XmlNode nLNP in nOS.ChildNodes)

{

if (nLNP.Name == "FormattedPrice")

{

Response.Write(

"strPrice");

String strPrice = nLNP.InnerXml; //our data !

break; //done looking here.

}

}

}

}

}

else if (nChild.Name == "EditorialReviews")

{

foreach (XmlNode nCR in nChild.ChildNodes)

{

foreach (XmlNode nRev in nCR.ChildNodes)

{

if (nRev.Name == "Content")

{

Response.Write(

"<br> Description:");

Response.Write(nRev.InnerXml);

//Our review text!

string strReview = nRev.InnerXml;

}

}

}

}

}

}

}

}

}

Sample creating Menu at master file using sql-server Table and keeping menu items at database using asp,net,C# , asp 2.0

Sample creating Menu at master file using sql-server Table and keeping menu items at database using asp,net,C# , asp 2.0 & menu control.

Table 

CREATE TABLE [dbo].[ovMenu] (
[MenuID] [int] IDENTITY (1, 1) NOT NULL ,
[Text] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Description] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ParentID] [int] NULL 
) ON [PRIMARY]
GO
sample data
MenuID Text Description ParentID
22 Overrides Commission
23 Reports Reports
31 Admin
32 Support Support
33 ABC 22
34 XYZ XYZ 22
35 ABC 23
36 XYZ XYZ 23
37 Detail Report overrep2 34
38 Summary Report ovsumrept 34
39 Adv Prc Error advprcerr 36
40 SRP Error srperrrep 36
41 Commission ovowncomrep 36
42 Enter Override ownerdetals 34
43 Update Override overupdate 34
44 Commission Default 35
46 Detail Report innoverrep1 33
47 Summary Report ovsuminnrep 33
48 Monthly Report ovsminnmth 33
49 Monthly Report ovsmsumrep 34
50 Source Report oversortblr 33
55 ABC 31
56 XYZ 31
57 Data Update 55
58 Full Update 55
59 Data Update 56
60 Unit Cost Error scUncstWTerr 36
61 Qtm. Override quantumov 33
62 ETC-EB etceb 36


XML

TransformXSLT.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes" encoding="utf-8"/>
  <!-- Find the root node called Menus 
       and call MenuListing for its children -->
  <xsl:template match="/Menus">
    <MenuItems>
      <xsl:call-template name="MenuListing" />
    </MenuItems>
  </xsl:template>
  
  <!-- Allow for recusive child node processing -->
  <xsl:template name="MenuListing">
    <xsl:apply-templates select="Menu" />
  </xsl:template>
  
  <xsl:template match="Menu">
    <MenuItem>
      <!-- Convert Menu child elements to MenuItem attributes -->
      <xsl:attribute name="Text">
        <xsl:value-of select="Text"/>
      </xsl:attribute>
      <xsl:attribute name="ToolTip">
        <xsl:value-of select="Description"/>
      </xsl:attribute>
      <xsl:attribute name="NavigateUrl">
        <xsl:text>?Sel=</xsl:text>
        <xsl:value-of select="Description"/>
      </xsl:attribute>
      
      <!-- Call MenuListing if there are child Menu nodes -->
      <xsl:if test="count(Menu) > 0">
        <xsl:call-template name="MenuListing" />
      </xsl:if>
    </MenuItem>
  </xsl:template>
</xsl:stylesheet>



Html Code

<%@ Master  Language="C#"  AutoEventWireup="true" CodeFile="MasterReport.master.cs" Inherits="MasterReport" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<head runat="server">
    <title>Untitled Page</title>



</head>
<body style="margin-top:2%; margin-left:2%; margin-right:2%; margin-bottom:2%; background-color:#6699ff; height:100%";  >
    <form id="form1" runat="server">
    <div>
        <table border="0" cellpadding="0" cellspacing="0"  style="width:100%; height:100%" id="TABLE1" onclick="return TABLE1_onclick()" >
            <tr>
                <td bgcolor="#000099" bordercolordark="#ffffff" colspan="2" style="height: 1%" valign="top"
                    width="100%">&nbsp;
                    </td>
            </tr>
            <tr>
                <td colspan="2" style="height: 1%;"   valign="top" bgcolor="#0033cc" width="100%" bordercolordark="#ffffff">
                    <font  color="white"> </font><span style="font-size: 20px; color: white">&nbsp;&nbsp;<br />
                        &nbsp; &nbsp;<strong>Sales Override &amp; Commission</strong></span><br />
                        
                        
                    &nbsp;</td>
            </tr>
            <tr>
                <td bgcolor="#000099" colspan="2" bordercolor="Red" style="height: 1%" valign="top" width="100%" bordercolordark="#ffffff" align="right">
                    <font color="#ffffff"><b>&nbsp;&nbsp;&nbsp;Welcome</b></font>
                    
                    <asp:Label ID="Label1"   runat="server" Text="Label" Width="57px" Font-Bold="True" ForeColor="White" BackColor="Transparent"></asp:Label>
                    
                   &nbsp; <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Logout" Height="20px" Width="52px"  />&nbsp;</td>
            </tr>
            <tr>
                <td  valign="top"  bgcolor="Lavender" width="20%">
                <table  cellspacing="0" cellpadding="15" border="0" width="99%" height="1%"  >
        <tr>
          
          <td valign="top" >
            <asp:contentplaceholder id="MainBody" runat="server"  >
                <asp:Menu ID="Menu1" runat="server" BackColor="Transparent" DataSourceID="xmlDataSource"
                    DynamicHorizontalOffset="1" Font-Names="arial" ForeColor="#990000" StaticDisplayLevels="1"
                    StaticSubMenuIndent="10px" Width="99%" BorderWidth="1" BorderColor="AliceBlue">
                    <DataBindings>
                     <asp:MenuItemBinding DataMember="MenuItem" NavigateUrlField="NavigateUrl" TextField="Text" 
                     ToolTipField="ToolTip"  />
                    </DataBindings>
                    <StaticSelectedStyle BackColor="Red" Font-Bold="true" BorderStyle="Solid" />
                    <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" BorderWidth="1px" BorderColor="AliceBlue" BorderStyle="Solid" Font-Bold="true"/>
                    <DynamicHoverStyle  BackColor="#ffffcc"  ForeColor="Black" BorderWidth="1px"  Font-Bold="true" BorderColor="AliceBlue" BorderStyle="Solid" />
                    <StaticHoverStyle BackColor="#ffffcc"  Font-Bold="True" ForeColor="Black" BorderStyle="Solid" />
                    <StaticMenuItemStyle BorderWidth="1px" BorderColor="AliceBlue" BorderStyle="Solid" HorizontalPadding="5px" VerticalPadding="2px" BackColor="#d8e4f8" Font-Bold="true" ForeColor="Blue"/>
                    <DynamicMenuStyle BorderWidth="1px"    BorderColor="AliceBlue" BorderStyle="Solid" HorizontalPadding="5px" VerticalPadding="2px" BackColor="#d8e4f8" Font-Bold="true" ForeColor="Blue"/>
                </asp:Menu>
                
            
      &nbsp;<asp:XmlDataSource ID="xmlDataSource" TransformFile="~/TransformXSLT.xsl" XPath="MenuItems/MenuItem" runat="server"/> 
          </asp:contentplaceholder>
            <div>
    </div>
            
          </td>
        </tr>
        
      </table>
      
                </td>
                <td  valign="top" align="left" bgcolor="white" width="100%" >
                <asp:contentplaceholder id="mainContent" runat="server">
                    
                </asp:contentplaceholder>
                </td>
            </tr>
            <tr>
                <td colspan="2" bgcolor="#0033cc" align="center" > <font color="#ffffff">©2007 xxxxxx LLC</font>
                </td>
            </tr>
            
        </table>
        
    </div>
    </form>
</body>
</html>





code behind

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.OleDb;

public partial class MasterReport : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        //Request.UserAgent.IndexOf("IE") != -1).

        if (Session["Usrid"]==null) 
        {
            Response.Redirect("Login.aspx");
        }


        Label1.Text = Session["Usrid"].ToString();
        Label1.ForeColor = System.Drawing.Color.White;

        {

            DataSet ds = new DataSet();
            string connStr = "server=SERVER;Initial Catalog=DB;User ID=DB;Password=DB";
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                string sql = "Select MenuID, Text, Description, ParentID from ovMenu";
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                da.Fill(ds);
                da.Dispose();
            }
            ds.DataSetName = "Menus";
            ds.Tables[0].TableName = "Menu";
            DataRelation relation = new DataRelation("ParentChild",
                    ds.Tables["Menu"].Columns["MenuID"],
                    ds.Tables["Menu"].Columns["ParentID"],
                    true);

            relation.Nested = true;
            ds.Relations.Add(relation);

            xmlDataSource.Data = ds.GetXml();

           // Response.Write(ds.GetXml());


            if (Request.Params["Sel"] != null)
                if (Request.Params["Sel"] == "Smart Circle")
                {
                    Response.Redirect("overrep2.aspx");
                }
                else
                   Response.Redirect(Request.Params["Sel"]+".aspx");
               

                
             //Page.Controls.Add(new System.Web.UI.LiteralControl("You selected " + Request.Params["Sel"]));
        }
    }




    protected void Button1_Click(object sender, EventArgs e)
    {
  FormsAuthentication.SignOut();
  FormsAuthentication.RedirectToLoginPage();

    }
}

Tuesday, March 24, 2009

The entry ConnectionString has already been added.

put <clear/> before <add , like following:
 
<
connectionStrings>

<

clear />

<

add name="ConnectionString" connectionString="Data Source=SERVERNAME;Initial Catalog=DATABASE;User ID=USER" providerName="System.Data.SqlClient"/>

Sunday, March 22, 2009

COALESCE With Like Sql-server

using COALESCE With Like in Sql-server
 
SELECT
* FROM PHONEMEMO WHERE phto like '%' + COALESCE(@phto, phto)+'%'
and
phfrom like '%' + COALESCE(@phfrom, phfrom)+'%'
 

Saturday, March 21, 2009

cursor style hand not working on gridview at firefox asp.net

cursor style hand not working on gridview at firefox

in your stylesheet use
cursor:pointer;

Tuesday, March 17, 2009

nchar and nvarchar SQL-SERVER 2005 MAX length

nchar [ ( n ) ]

Fixed-length Unicode character data of n characters. n must be a value from 1 through 4,000. The storage size is two times n bytes. The ISO synonyms for nchar are national char and national character.

nvarchar [ ( n | max ) ]

Variable-length Unicode character data. n can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size, in bytes, is two times the number of characters entered + 2 bytes. The data entered can be 0 characters in length. The ISO synonyms for nvarchar are national char varying and national character varying.

Data export/Import sql-server 2005

Click on database after that on Tasks after that import data/Export data.....

Sunday, March 15, 2009

Create a webservice directly from Sql Server 2005 using HTTP

Create stored procedure to return list of employeesuse adventureworks
go

create procedure dbo.GetEmployees
As
select e.employeeid, e.title, c.FirstName + ' ' + c.Lastname As Fullname from HumanResources.employee e
inner join person.contact c
on e.contactid = c.contactid
go

The Sql 2005 code to create the HTTP ENDPOINTuse adventureworks
go

CREATE ENDPOINT GetEmployees
    STATE = STARTED
AS HTTP
(
    PATH = '/Employee',
    AUTHENTICATION = (INTEGRATED),
    PORTS = (CLEAR),
    SITE = 'localhost'
)
FOR SOAP
(
    WEBMETHOD 'EmployeeList'
        (NAME='AdventureWorks.dbo.GetEmployees'),
    BATCHES = DISABLED,
    WSDL = DEFAULT,
    DATABASE = 'AdventureWorks',
    NAMESPACE = 'http://AdventureWorks/Employee'
)

A VB.net form that loads the results of the stored procedure into a list box.

Public Class Form1

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' Create a new instance of the web service

        Dim employeesProxy As adventureWorksService.GetEmployees = New adventureWorksService.GetEmployees

 

        ' You have to pass in credentials to authenticate yourself to use the service.  We are just going to use

        '   the same credentials we have logged into our computer as.

        employeesProxy.Credentials = System.Net.CredentialCache.DefaultCredentials

 

        ' The result of a SELECT statement via an endpoint can be converted to a DataSet

        Dim ds As System.Data.DataSet = DirectCast(employeesProxy.EmployeeList, DataSet)

 

        ListBox1.DataSource = ds.Tables(0)

        ListBox1.DisplayMember = "FullName"

        ListBox1.ValueMember = "EmployeeId"

 

    End Sub

End Class

 

--

Friday, March 13, 2009

Setup Check printing needs to defined following In JD Edwards

Setup Check printing needs to defined following In JD Edwards
 

F0417  - Define AC# and program Name for Check Printing  Program name.
P0030G – Enter Account detail.
R04570 - Set Processing Option with GL bank Account in printing tab.

 
 

Wednesday, March 11, 2009

Date and Time Operation mysql

mysql> SELECT DATE_ADD('2008-01-02', INTERVAL 31 DAY);
        -> '2009-02-02'
mysql> SELECT ADDDATE('2009-01-02', INTERVAL 31 DAY);
        -> '2009-02-02'

mysql> SELECT ADDTIME('2007-12-31 23:59:59.999999', '1 1:1:1.000002');
        -> '2009-01-02 01:01:01.000001'
mysql> SELECT ADDTIME('01:00:00.999999', '02:00:00.999998');
        -> '03:00:01.999997'


mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
        -> '2004-01-01 13:00:00'
mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00');
        -> '2004-01-01 22:00:00'

mysql> SELECT CURDATE();
        -> '2009-06-13'
mysql> SELECT CURDATE() + 0;
        -> 20090613

mysql> SELECT CURTIME();
        -> '23:50:26'
mysql> SELECT CURTIME() + 0;
        -> 235026.000000
mysql> SELECT DATE('2005-12-31 01:02:03');
        -> '2005-12-31'

mysql> SELECT DATEDIFF('2007-12-31 23:59:59','2007-12-30');
        -> 1
mysql> SELECT DATEDIFF('2010-11-30 23:59:59','2010-12-31');

Tuesday, March 10, 2009

Login Authentication Access Database also access database connection in C# Asp.net 2.0,3.5

Login Authentication Access Database also access database connection
in C# Asp.net 2.0,3.5


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class signon : System.Web.UI.Page
{
string CaseIDClient;
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated = false;
Authenticated =
SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Authenticated;
if (Authenticated == true)
{

Response.Redirect("Default.aspx");

}

}
private bool SiteLevelCustomAuthenticationMethod(string UserName,
string Password)
{
OleDbConnection conDatabase = null;
OleDbDataReader Dr = null;

bool boolReturnValue = false;
string strUserID = UserName;
conDatabase = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\\sites\\Single15\\visli\\database\\H4rDB.mdb");
conDatabase.Open();

string strSQL = "select * from USERS where USERID=\'" +
(strUserID + "\'");

OleDbCommand cmdDatabase = new OleDbCommand(strSQL, conDatabase);
Dr = cmdDatabase.ExecuteReader();

while (Dr.Read())
{
string UserNameDB = Dr["USERID"].ToString();
string PasswordDB = Dr["PASSWORD"].ToString();
string userbranchDB = Dr["USERBRANCH"].ToString();
string userRoleDB = Dr["ROLE"].ToString();


if ((UserName == UserNameDB.TrimEnd().TrimStart()) &
(Password == PasswordDB.TrimEnd().TrimStart()))
{
Session["loginm"] = strUserID;

Session["userRole"] = userRoleDB;
Session["userBranch"] = userbranchDB;
Session["BRANCH"] = userbranchDB;

Session["CaseIDClient"] = Dr["CASENO"];
boolReturnValue = true;
break;

}

}
conDatabase.Close();
Dr.Close();
return boolReturnValue;
}


}

Friday, March 6, 2009

System.Data.OleDb.OleDbException: Too many fields defined.

Too many fields defined.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

my solution
break your insert and update statement in 2-3 parts and try.
 

Thursday, March 5, 2009

Hide and Show table asp.net c# 2.0 3.5

Hide and Show table asp.net c# 2.0 3.5

Html
<table id="tab1"  runat="server">

code Behind to hide
tab1.Visible = false;
code Behind to show
tab1.Visible = true;
 

Wednesday, March 4, 2009

Turning off Arithmetic Overflow error converting float to data type numeric.

Arithmetic overflow error converting float to data type numeric.The statement has been terminated.
Use following statement in your stored proc
 
SET ANSI_WARNINGS OFF
SET ARITHABORT OFF