Monday, 25 June 2012

Find version of sqlserver


select @@version

ajaxcascading dropdown


Client
 <%@ register namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagprefix="ajax" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="scriptmanager1" runat="server">
        </asp:ScriptManager>
        <div>
            <table>
                <tr>
                    <td>
                        Select Country:
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlcountry" runat="server">
                        </asp:DropDownList>
<ajax:CascadingDropDown ID="ccdCountry" runat="server" Category="Country" TargetControlID="ddlcountry"
PromptText="Select Country" LoadingText="Loading Countries.."       ServiceMethod="BindCountryDetails"
                            ServicePath="CascadingDropdown.asmx">
                        </ajax:CascadingDropDown>
                    </td>
                </tr>
                <tr>
                    <td>
                        Select State:
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlState" runat="server">
                        </asp:DropDownList>
   <ajax:CascadingDropDown ID="ccdState" runat="server"  Category="State" ParentControlID="ddlcountry"
TargetControlID="ddlState" PromptText="Select State"    LoadingText="Loading States.."
           ServiceMethod="BindStateDetails" ServicePath="CascadingDropdown.asmx">
                        </ajax:CascadingDropDown>
                    </td>
                </tr>
            </table>
        </div>
        </form>
    </body>
    </html>


Webservice
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using AjaxControlToolkit;


/// <summary>
/// Summary description for CascadingDropdown
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class CascadingDropdown : System.Web.Services.WebService
{
//Database connection string
private static string strconnection = ConfigurationManager.AppSettings["ConnectionString"].ToString();
//database connection
SqlConnection concountry = new SqlConnection(strconnection);
public CascadingDropdown () {

//Uncomment the following line if using designed components
//InitializeComponent();
}
/// <summary>
/// WebMethod to Populate COuntry Dropdown
/// </summary>
[WebMethod]
public CascadingDropDownNameValue[] BindCountryDetails(string knownCategoryValues,string category)
{
concountry.Open();
SqlCommand cmdcountry = new SqlCommand("select * from Country", concountry);
cmdcountry.ExecuteNonQuery();
SqlDataAdapter dacountry = new SqlDataAdapter(cmdcountry);
DataSet dscountry = new DataSet();
dacountry.Fill(dscountry);
concountry.Close();
//create list and add items in it by looping through dataset table
List<CascadingDropDownNameValue> countrydetails = new List<CascadingDropDownNameValue>();
foreach(DataRow dtrow in dscountry.Tables[0].Rows)
{
string CountryID = dtrow["CountryID"].ToString();
string CountryName = dtrow["CountryName"].ToString();
countrydetails.Add(new CascadingDropDownNameValue(CountryName, CountryID));
}
return countrydetails.ToArray();
}
/// <summary>
/// WebMethod to Populate State Dropdown
/// </summary>
[WebMethod]
public CascadingDropDownNameValue[] BindStateDetails(string knownCategoryValues,string category)
{
int countryID;
//This method will return a StringDictionary containing the name/value pairs of the currently selected values
StringDictionary countrydetails =AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
countryID = Convert.ToInt32(countrydetails["Country"]);
concountry.Open();
SqlCommand cmdstate = new SqlCommand("select * from State where CountryID=@CountryID", concountry);
cmdstate.Parameters.AddWithValue("@CountryID", countryID);
cmdstate.ExecuteNonQuery();
SqlDataAdapter dastate = new SqlDataAdapter(cmdstate);
DataSet dsstate = new DataSet();
dastate.Fill(dsstate);
concountry.Close();
//create list and add items in it by looping through dataset table
List<CascadingDropDownNameValue> statedetails = new List<CascadingDropDownNameValue>();
foreach (DataRow dtrow in dsstate.Tables[0].Rows)
{
string StateID = dtrow["StateID"].ToString();
string StateName = dtrow["StateName"].ToString();
statedetails.Add(new CascadingDropDownNameValue(StateName, StateID));
}
return statedetails.ToArray();
}


need to write webmethods this format only

In More Detail



Drop Time in DateTime-SQL


SELECT DATEADD(dd, DATEDIFF(d, 0, Getdate()), 0)

Result
2012-06-25 00:00:00.000

Determine No of users connected to sqlserver database


select spid, status, loginame, hostname, blocked, db_name(dbid),
cmd from master..sysprocesses where db_name(dbid) = 'IMarque_db'
and spid>50

Find Index on a table


sp_helpindex 'tablename'

Friday, 22 June 2012

Invalid postback or callback argument. Event validation is enabled using in configuration..


Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Solution
          <%@ Page EnableEventValidation="false" %>



Encrypt or Decrypt Connection Strings in web.config file using ASP.NET in IIS


In Command Prompt, Goto this location and type that command
C:\Windows\Microsoft.Net\Framework\v2.0.50727
(this v2.0.50727 folder contains  aspnet_regiis.exe )

Encrypt connectionStrings  in web.config of IIS based site:
aspnet_regiis.exe -pe "connectionStrings" –app "/SampleWebSite”

Decrypt connectionStrings in web.config of IIS based site:
aspnet_regiis.exe -pd "connectionStrings" –app "/SampleWebSite