Monday, January 6, 2014

Populate TreeView From DataBase Using Recursive Function

Table Name: accountheads

IID Name ParentID
1 Test01 0
2 Test001 1
3 Test002 1
4 Test02 0
5 Test001 4
6 Test002 4
7 Test003 6


protected DataSet PDataset(string select_statement)
{
            SqlConnection _con = new SqlConnection("DataSource(Local); 
            database =DATABASE NAME ; UserID=sa;Password=******");
            SqlDataAdapter ad = new SqlDataAdapter(select_statement, _con);
            DataSet ds = new DataSet();
            ad.Fill(ds);
            _con.Close();
            return ds;
}


 public void Load_tree()
 {
            DataSet PrSet = PDataset("SELECT * FROM accountheads");
            treeView1.Nodes.Clear();
            foreach (DataRow dr in PrSet.Tables[0].Rows)
            {
                if ((int)dr["ParentID"] ==  0 )
                {
                    TreeNode tnParent = new TreeNode();
                    tnParent.Text = dr["Name"].ToString();
                    string value = dr["ID"].ToString();
                    tnParent.Expand();
                    treeView1.Nodes.Add(tnParent);
                    FillChild(tnParent, value);
                 }
             }
}

        public int FillChild(TreeNode parent,string ID)
        {

            DataSet ds = PDataset("SELECT * FROM tree WHERE ParentID =" + ID );
            if (ds.Tables[0].Rows.Count > 0)
            {

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    TreeNode child = new TreeNode();
                    child.Text = dr["Name"].ToString().Trim();
                    string temp = dr["ID"].ToString();
                    child.Collapse();
                    parent.Nodes.Add(child);
                    FillChild(child, temp);
                }
                return 0;
            }
            else 
            {
                return 0;
            }
                                                          
        }

Wednesday, December 18, 2013

The operation has timed out. While deploying SSRS


Check all following conditions:
----------------------------------

Step :1
  1. The connection string for the data source, which is - Connect Timeout=100
  2. Tools>Options>Database Tools>Query and View Designers. Cancel long running query is set to 100 or max 60000
  3. Tools>Options>Database Tools>Table and Database Designers>Checked 'Override Connection String time-out value for table designer updates. Transaction time-out after is set to 100 or max 60000
Step :2 
  1. Open your web browser on the server and go to http://localhost:80/Reports
  2. Navigate to the Report location and click on the problem report(s).
  3. On the left-hand pane, click on Properties.
  4. In the ‘Report Execution Timeout’ click the ‘Do not timeout report execution’. (via
Step:3

Set the HttpRuntime ExecutionTimeout
  1. Open the ReportServer’s Web.config file by going to Start -> Administrative Tools -> Internet Information Services.
  2. From there, expand Web Sites -> Default Web Site, and click on ReportServer. On the right-hand pane, right-click ‘Web.Config’ and select ‘Open’.
  3. Locate the HttpRuntime parameter. If it doesn’t exist, you will have to create it within the section.
  4. Set the executionTimeout value to ‘10800’ (3 hours) as shown below:

    
Step: 4
Tools>Options>Database Tools>Table and Database Designers> check the option  prevent saving changes that requires table re-creation 
step: 5 
also check your results by executing the procedure or SQLstatement


Wednesday, November 20, 2013

how to change en-US dates to en-GB for asp.net? ( M/d/yyyy to dd/MM/yyyy)

  • en-US: M/d/yyyy (e.g. 3/14/2012)
  • en-GB: dd/MM/yyyy (e.g. 14/03/2012)
 do the following in web.config file


<configuration/>
<system.web/>
<globalization culture="en-GB"/> 
</system.web>
</configuration> 
 
 

 

Friday, November 15, 2013

503 service unavailable IIS OR Application pool stops automatically in IIS7

SharePoint:
 
503 service unavailable:

application pool stops so you start the application pool of the web Application.

I got this error message when my application pool run with user Identity.

.Net:

1.you are given wrong user name or password you got this error message.

Do the following changes in application pool.

1.click on the application pool
2.click on advanced setting on the right pane.
3.click on Identity Under the process model.
4.select built in account under this user network(Ex:network service )
5.select custom account give user name and password


 

Wednesday, November 6, 2013

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified

CASE 1: if you are used order by clause in the following view
SELECT  
  C.customer_id
, C.customer_code
, C.customer_type_id
A.mobile ,A.email , A.phone
FROM clinic_customers C INNER JOIN address_details A ON A.address_id=C.address_id
order by C.last_update_on desc

You got following error message

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified

do small change above code as follows it is working fine
CASE 2: if you can use order by clause in the following view
SELECT   TOP 100 PERCENT 
  C.customer_id
, C.customer_code
, C.customer_type_id
A.mobile ,A.email , A.phone
FROM clinic_customers C INNER JOIN address_details A ON A.address_id=C.address_id
order by C.last_update_on desc

Tuesday, September 3, 2013

cannot use a leading .. to exit above the top directory

Solution 1

It means that one of the paths has a ".." at the beginning of it that would result in exiting the web site's root folder hierarchy. You need to google "asp.net relative paths" or something like that to help you with your problem.

BTW, a hint to where the problem is is included in the exception page that you saw. It will actually tell you what file it found the problem in.

To head off future occurences of this exception, do a search in the entire solution for this string: "../". If you find any of those in files in the root path of your web site, address them.

Tuesday, July 16, 2013

Text and Value Pairs with AutoCompleteExtender and Display record in Gridview

We know how to use AutoComplete control to display suggestions as you enter text into a TextBox.  
However, as we know AutoComplete control only retrieves text and no values. In sort, AutoComplete 
only retrieves text and no IDs.  You might be thinking what use of IDs ?. An example of where we have
 multiple tables and we store ID in foreign table instead of text. Consider a scenario, where you have to
 search for department name and for that particular department, you have to display its employee data
 from employee table and in that department id has been stored. For this you will store department ID
 into employee table. Here where Text and Value Pairs with AutoComplete control is useful.

The AutoComplete contorl includes a static method named CreateAutoCompeleteItem() that returns a single
 string that represents a text and value pair. You can use this method when returning a string array from the
 GetSuggestions() method to include a primary key with each suggestion.

A TextBox control, however, can represent only a single value. In order to represent the ID of the selected
text, you need to add a hidden form field to your page.You can update the value of the hidden field whenever
 a user selects a new suggestions

I will explain here part by part.
[System.Web.Services.WebMethod]
public static string[] GetSuggestions(string prefixText, int count)
{
 try
 {        
   string constr=string.Empty;
   constr= WebConfigurationManager.ConnectionStrings["ConnectionString"].
   ConnectionString;
   string sqlQuery = "SELECT [FirstName],[CustomerID] FROM [Customer] 
   WHERE FirstName like @FirstName"; 
   SqlConnection conn = new SqlConnection(conStr);
   SqlCommand cmd=new SqlCommand(sqlQuery,conn);
   cmd.Parameters.AddWithValue("@FirstName", prefixText + "%");
   conn.Open(); 
   SqlDataReader dr = cmd.ExecuteReader();
   List<string> custList = new List<string>();
   string custItem = string.Empty; 
   while (dr.Read())
   {
      custItem=AutoCompleteExtender.CreateAutoCompleteItem(dr[0].ToString(),
       dr[1].ToString());
      custList.Add(custItem);      
   } 
   conn.Close();
   dr.Close(); 
   return custList.ToArray();      
 }
 catch (Exception ex)
 {
    throw ex;
 }
}

Instead of creating web service, I am creating into same page by adding [System.Web.Services.WebMethod]. 
In First part, with prefix I am fetching records and bind into DataReader.  In Second part, I am
looping datareader and calling the AutoCompelteExtender.CreateAutoCompleteItem() method 
and adding into List collections variable custList, and returing array of customer.
The AutoComplete extender is declaration as below :-
<cc1:AutoCompleteExtender ID="ace" TargetControlID="txtCustName" 
ServiceMethod="GetSuggestions"   MinimumPrefixLength="2" 
OnClientItemSelected="ace_itemSelected" FirstRowSelected="true"
runat="server" />

The AutoCompelte extender control includes an OnClientItemSelected property. When a new
 suggestion is selected, the ace_itemSelected()  JavaScript method executes.

The ace_ItemSelected() method updates the value of the HiddenField with the value of the selected 
suggestion. The JavaScript method looks like below :-
function ace_itemSelected(sender, e)
{
  var hdCustID = $get('<%= hdCustID.ClientID %>');
  hdCustID.value = e.get_value();
}

The second parameter passed to the JavaScript method includes a value property that represents the primary key
 of the selected suggestion. The primary key is assigned to the hidden field so that it can be read when the page
 is posted back to the server.

When you select a text, an OnTextChanged() event will occur and fetch record from database for that particular
 customer  and display into grid. Code looks like below :-
protected void txtCustName_TextChanged(object sender, EventArgs e)
{
  gvCustomer.DataSource= GetCustomerDetail(Convert.ToInt32(hdCustID.Value));
  gvCustomer.DataBind();
}

public SqlDataReader GetCustomerDetail(int CustID)
{
   try
   {
     string conStr;
     conStr = WebConfigurationManager.ConnectionStrings["MyBlogConnectionString"]
    .ConnectionString;
     string sqlQuery = "SELECT CustomerID,FirstName,MiddleName,LastName,Desgination,
     Address,City,";
     sqlQuery=sqlQuery + "State,Country FROM [Customer] WHERE CustomerID = 
     @CustomerID"; 
     SqlConnection conn = new SqlConnection(conStr);
     SqlCommand cmd = new SqlCommand(sqlQuery, conn);
     cmd.Parameters.AddWithValue("@CustomerID", CustID); 
     conn.Open();
     return cmd.ExecuteReader(CommandBehavior.CloseConnection);
  }
   catch (Exception ex)
   {
      throw ex;
   }
}
After selecting value from textbox, output look like below :-


Cust
  

follow links:
http://weblogs.asp.net/manojkdotnet/archive/2009/11/30/text-and-value-pairs-with-autocompleteextender
-and-display-record-in-gridview.aspx

http://www.aspsnippets.com/Articles/Fetch-multiple-values-as-Key-Value-pair-in-ASP.Net-AJAX-
AutoCompleteExtender.aspx