[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Variable not looping through a datagrid

Posted on 2004-10-25
12
Medium Priority
?
252 Views
Last Modified: 2010-04-15
Hi

Can anyone help solve this problem, I have just being informed on how to highlight a variable using regex, the problem now is when I enter the variable into the datagrid, all the pagedescriptions are the same even through the rest of the results change correctly.

i.e title and pageurl change for each record, but the description is the same for each. Can anyone help solve this problem.

Below is the code:

void Page_Load(Object Src, EventArgs E)
{
inputString = Request.QueryString["TxtQuery"];
                              string[] words = GetQueryStringToArray(Request.QueryString["TxtQuery"].ToString()) ;
                    Word1 = words[0];
                    Word2 = words[1];
                    Word3 = words[2];
                    Word4 = words[3];
                    Word5 = words[4];
                    Word6 = words[5];
                              HighlightWord = spQueryResults.FieldValue("PageDescription", null);
                    HighlightWord = Regex.Replace(HighlightWord, Word1, "<strong>"+Word1+"</strong>", RegexOptions.IgnoreCase);
                    HighlightWord = Regex.Replace(HighlightWord, Word2, "<strong>"+Word2+"</strong>", RegexOptions.IgnoreCase);
                   
               
          }
     public string[] GetQueryStringToArray(string inputString)
          {
              string[] finalSetOfWords = new string[6];
               char[] separators = {' '};
               string[] words = inputString.Split(separators);
               
               for ( int i=0; i < 6; i++)
               {
                    if(words.Length > i && inputString.Trim().Length > 0)
                    {
                         finalSetOfWords[i] = words[i];
                    }
                    else
                    {
                         finalSetOfWords[i] = "NNN";
                    }
               }
               return finalSetOfWords;
                    
          }

Datadrid details
<Columns>
          <asp:TemplateColumn  runat="server">
<itemtemplate>
             
              <span class="QuCssResultsTitle"><%# spQueryResults.FieldValue("PageTitle", Container) %></span><br>
              <span class="QuCssResultsBody"><%=HighlightWord%></span><br>
            <span class="QuCssResultsURL"><a href="<%# spQueryResults.FieldValue("PageURL", Container) %>"><%# spQueryResults.FieldValue("PageURL", Container) %></a></span></p><br>
        </itemtemplate></asp:TemplateColumn>
      </columns>

Any help would be appreciated
Caz

0
Comment
Question by:BeginningWebDesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 7

Expert Comment

by:sukumar_diya
ID: 12409053
Hi pal,
Please mention the details about the declaration of the variable 'HighlightWord' if possible post full code here. I checked with information given by you its working fine.. The following code is the one i checked..

protected string HighlightWord="harry new";
            private void Page_Load(object sender, System.EventArgs e)
            {
                  
                  string word1="harry";
                  
                  HighlightWord = Regex.Replace(HighlightWord, word1, "<strong>" + word1 + "</strong>", RegexOptions.IgnoreCase);
                  DataColumn dtcol = new DataColumn("test");
                  DataTable dttbl =new DataTable();
                  dttbl.Columns.Add(dtcol);
                  DataRow dtrow=dttbl.NewRow();
                  dttbl.Rows.Add(dtrow);
                  DataGrid1.DataSource=dttbl;
                  DataGrid1.DataBind();
}

Html
++++
      <asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
           
           
            <span class="QuCssResultsBody"><%=HighlightWord%></span><br>
         
       
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn></asp:TemplateColumn>
</Columns>

                  </asp:DataGrid><br>







0
 

Author Comment

by:BeginningWebDesign
ID: 12416618
Hi sukumar_diya

Sorry for delay had to go out and only got back at 10pm tonight, please find full code below.


void Page_Load(Object Src, EventArgs E)
{
inputString = Request.QueryString["TxtQuery"];
                              string[] words = GetQueryStringToArray(Request.QueryString["TxtQuery"].ToString()) ;
                    Word1 = words[0];
                    Word2 = words[1];
                    Word3 = words[2];
                    Word4 = words[3];
                    Word5 = words[4];
                    Word6 = words[5];
                              HighlightWord = spQueryResults.FieldValue("PageDescription", null);
                    HighlightWord = Regex.Replace(HighlightWord, Word1, "<strong>"+Word1+"</strong>", RegexOptions.IgnoreCase);
                    HighlightWord = Regex.Replace(HighlightWord, Word2, "<strong>"+Word2+"</strong>", RegexOptions.IgnoreCase);
                              HighlightWord = Regex.Replace(HighlightWord, Word3, "<strong>"+Word3+"</strong>", RegexOptions.IgnoreCase);
                    HighlightWord = Regex.Replace(HighlightWord, Word4, "<strong>"+Word4+"</strong>", RegexOptions.IgnoreCase);
                              HighlightWord = Regex.Replace(HighlightWord, Word5, "<strong>"+Word5+"</strong>", RegexOptions.IgnoreCase);
                    HighlightWord = Regex.Replace(HighlightWord, Word6, "<strong>"+Word6+"</strong>", RegexOptions.IgnoreCase);
                    DataColumn dtcol = new DataColumn("test");
                    DataTable dttbl =new DataTable();
                    dttbl.Columns.Add(dtcol);
                    DataRow dtrow=dttbl.NewRow();
                    dttbl.Rows.Add(dtrow);
                    QueryResults.DataSource=dttbl;
                    QueryResults.DataBind();


               
          }
     public string[] GetQueryStringToArray(string inputString)
          {
              string[] finalSetOfWords = new string[6];
               char[] separators = {' '};
               string[] words = inputString.Split(separators);
               
               for ( int i=0; i < 6; i++)
               {
                    if(words.Length > i && inputString.Trim().Length > 0)
                    {
                         finalSetOfWords[i] = words[i];
                    }
                    else
                    {
                         finalSetOfWords[i] = "NNN";
                    }
               }
               return finalSetOfWords;
                    
          }

</script>

<form runat="server">
  <asp:DataGrid
  AllowCustomPaging="true"
  AllowPaging="true"
  AllowSorting="false"
  AutoGenerateColumns="false" BorderWidth="0"
  CellPadding="0"
  CellSpacing="0"
  DataSource="<%# spQueryResults.DefaultView %>" id="QueryResults"
  PagerStyle-Mode="NextPrev"
  PagerStyle-NextPageText="Next --&gt;"
  PagerStyle-PrevPageText="&lt;-- Prev."
  PageSize="<%# spQueryResults.PageSize %>"
  runat="server"
  ShowFooter="true"
  ShowHeader="false"
  OnPageIndexChanged="spQueryResults.OnDataGridPageIndexChanged"
  VirtualItemCount="<%# spQueryResults.RecordCount %>" gridline="None"
>
    <HeaderStyle/>
    <ItemStyle CssClass="QuCssResults"/>
    <AlternatingItemStyle CssClass="QuCssResults"/>
    <FooterStyle/>
    <PagerStyle CssClass="QuCssResultsNav"/>
    <Columns>
          <asp:TemplateColumn  runat="server">
            <itemtemplate>
              <p><div style="float:right;"><span class="QuCssResultsRele">&nbsp;</span></div><br>
              <span class="QuCssResultsTitle"><%# spQueryResults.FieldValue("PageTitle", Container) %></span><br>
              <span class="QuCssResultsBody"><%=HighlightWord%></span><br>
            <span class="QuCssResultsURL"><a href="<%# spQueryResults.FieldValue("PageURL", Container) %>"><%# spQueryResults.FieldValue("PageURL", Container) %></a> </span></p><br>
        </itemtemplate></asp:TemplateColumn>
      </columns>
  </asp:DataGrid>
</form>

When I try the code, I receive the following error:

Compiler Error Message: CS0246: The type or namespace name 'DataColumn' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

 

Line 118:                              HighlightWord = Regex.Replace(HighlightWord, Word5, "<strong>"+Word5+"</strong>", RegexOptions.IgnoreCase);
Line 119:                    HighlightWord = Regex.Replace(HighlightWord, Word6, "<strong>"+Word6+"</strong>", RegexOptions.IgnoreCase);
Line 120:                    DataColumn dtcol = new DataColumn("test");
Line 121:                    DataTable dttbl =new DataTable();
Line 122:                    dttbl.Columns.Add(dtcol);
 

Source File: C:\***\results.aspx    Line: 120

Caz
0
 
LVL 7

Expert Comment

by:sukumar_diya
ID: 12418789
Hi pal,
I have posted the code that is working for me. Please check with that ....

HTML CODE
+++++++++

<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="DRDa.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 

<html>
  <head>
    <title>WebForm2</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
   
  </head>
  <body MS_POSITIONING="GridLayout">
      
   <form runat="server" ID="Form1">
  <asp:DataGrid
  AllowCustomPaging="true"
  AllowPaging="true"
  AllowSorting="false"
  AutoGenerateColumns="false" BorderWidth="0"
  CellPadding="0"
  CellSpacing="0"
  id="QueryResults"
  PagerStyle-Mode="NextPrev"
  PagerStyle-NextPageText="Next --&gt;"
  PagerStyle-PrevPageText="&lt;-- Prev."
  runat="server"
  ShowFooter="true"
  ShowHeader="false"
 
  gridline="None"
>
    <HeaderStyle/>
    <ItemStyle CssClass="QuCssResults"/>
    <AlternatingItemStyle CssClass="QuCssResults"/>
    <FooterStyle/>
    <PagerStyle CssClass="QuCssResultsNav"/>
    <Columns>
         <asp:TemplateColumn  runat="server">
           <itemtemplate>
            <p><div style="float:right;"><span class="QuCssResultsRele">&nbsp;</span></div><br>
            <span class="QuCssResultsTitle">title</span><br>
            <span class="QuCssResultsBody"><%=HighlightWord%></span><br>
          <span class="QuCssResultsURL"><a href="url">url</a> </span></p><br>
       </itemtemplate></asp:TemplateColumn>
     </columns>
  </asp:DataGrid>
</form>

      
  </body>
</html>


Code Behind
+++++++++

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
namespace DRDa
{
      /// <summary>
      /// Summary description for WebForm2.
      /// </summary>
      public class WebForm2 : System.Web.UI.Page
      {
            protected System.Web.UI.WebControls.DataGrid QueryResults;
            protected string inputString="";
            protected string Word1="";
            protected string Word2="";
            protected string Word3="";
            protected string Word4="";
            protected string Word5="";
            protected string Word6="";
            protected string HighlightWord="";
            void Page_Load(Object Src, EventArgs E)
            {
                  inputString = "harry john test test2 test3 test4";
                  string[] words = GetQueryStringToArray(inputString) ;
                  Word1 = words[0];
                  Word2 = words[1];
                  Word3 = words[2];
                  Word4 = words[3];
                  Word5 = words[4];
                  Word6 = words[5];
                  HighlightWord = "i am testing with the name harry";
                  HighlightWord = Regex.Replace(HighlightWord, Word1, "<strong>" + Word1 + "</strong>", RegexOptions.IgnoreCase);
                  HighlightWord = Regex.Replace(HighlightWord, Word2, "<strong>" + Word2 + "</strong>", RegexOptions.IgnoreCase);
                  HighlightWord = Regex.Replace(HighlightWord, Word3, "<strong>" + Word3 + "</strong>", RegexOptions.IgnoreCase);
                  HighlightWord = Regex.Replace(HighlightWord, Word4, "<strong>" + Word4 + "</strong>", RegexOptions.IgnoreCase);
                  HighlightWord = Regex.Replace(HighlightWord, Word5, "<strong>" + Word5 + "</strong>", RegexOptions.IgnoreCase);
                  HighlightWord = Regex.Replace(HighlightWord, Word6, "<strong>" + Word6 + "</strong>", RegexOptions.IgnoreCase);
                   
                  DataColumn dtcol = new DataColumn("test");
                  DataTable dttbl =new DataTable();
                  dttbl.Columns.Add(dtcol);
                  DataRow dtrow=dttbl.NewRow();
                  dttbl.Rows.Add(dtrow);
                   
                  QueryResults.DataSource=dttbl;
                  QueryResults.DataBind();


               
            }
            public string[] GetQueryStringToArray(string inputString)
            {
                  string[] finalSetOfWords = new string[6];
                  char[] separators = {' '};
                  string[] words = inputString.Split(separators);
               
                  for ( int i=0; i < 6; i++)
                  {
                        if(words.Length > i && inputString.Trim().Length > 0)
                        {
                              finalSetOfWords[i] = words[i];
                        }
                        else
                        {
                              finalSetOfWords[i] = "NNN";
                        }
                  }
                  return finalSetOfWords;
                 
            }



            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
                  this.Load += new System.EventHandler(this.Page_Load);
            }
            #endregion
      }
}


Cheers
Sukumar
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:BeginningWebDesign
ID: 12419325
Hi sukumar_diya

Please bear with me for a while, I use Dreamweaver MX and the problem seems to be with how Dreamweaver databinds the datagrid.

I do have visual studio but I don't use it because

1) I cannot work out how to connect to the database using a web config file
2) I cannot work out how to put the stored procudures on the page and databind them to the datagrid

I will get back to you shortly once I have worked out how to do the above and then test your code.

Regards
Caz
0
 
LVL 7

Expert Comment

by:sukumar_diya
ID: 12419422
Hi pal,

In wen.config file make your connection string like below

<appSettings>
<add key="CONNECTIONSTRING" value="SERVER=#########;DATABASE=######;UID=#####;PWD=#####;Application Name=#####" />
</appSettings>

and you can get the connection string in the class as

string strConnection = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection objConnection;
SqlDataAdapter objAdapter;
DataTable objDataTable=new DataTable();

objConnection = new SqlConnection(strConnection);
objAdapter = new SqlDataAdapter("your stored procedure name", objConnection);
objAdapter.Fill(objDataTable);

datagrid.datasource= objDataSet .Tables[0];
datagrid.DataBind();

objDataTable=null;
dataAdapterObject.Dispose();
dataAdapterObject = null;
connectionObject.Close();
connectionObject.Dispose();
connectionObject = null;

I am using sql server. Hope it helps you...

cheers
Sukumar

0
 

Author Comment

by:BeginningWebDesign
ID: 12419520
Hi Sukumar

I'm using sql server too.

I have the following

string SearchPhrase;
SearchPhrase = Request.QueryString["txtSearch"];

How would I get the value of SearchPhrase and use it to search the stored procedure to return the results. Dreamweaver makes it so easy, that it hard to start and change to visual studio.

Caz
0
 
LVL 7

Expert Comment

by:sukumar_diya
ID: 12419624
hi Caz,
I have posted some code here try with that hope it will help you...
Cheers
Sukumar

            private void Page_Load(object sender, System.EventArgs e)
            {
                  string SearchPhrase;      
                  if( Request.QueryString["txtSearch"]!=null)
                  {
                        SearchPhrase = Request.QueryString["txtSearch"];
                                                                DataTable dtTbl = searchfuntion(SearchPhrase,"");
                        datagrid.DataSource= dtTbl;
                        datagrid.DataBind();
                  }
            }

            public DataTable searchfuntion(string param1,string param2)
            {
                  SqlParameter[] colParams = new SqlParameter[2];
                  try
                  {
                        colParams[0] = new SqlParameter("@group_Name",param1);
                        colParams[1] = new SqlParameter("@group_Desc",param2);
                        return ExecuteSQL("usp_anchorage_group_master_insert",colParams);
                  }
                  catch(Exception ex)
                  {
                        throw ex;
                  }
            }      

            /// <summary>
            /// Executes the Stored Procedure with the SqlParameter array object passed
            /// and returns the DataSet
            /// </summary>
            /// <param name="CommandText"></param>
            /// <param name="Params"></param>
            /// <returns></returns>
            private static DataSet ExecuteSQL(String CommandText,SqlParameter[] Params)
            {
                  OpenConnection();
                  SqlCommand cmdObj=new SqlCommand();
                  cmdObj.CommandType=CommandType.StoredProcedure;
                  cmdObj.Connection=Conn;
                  cmdObj.CommandText=CommandText;
                  if (Params.Length>0)
                  {
                        for (int i=0;i<Params.Length;i++)
                        {
                              cmdObj.Parameters.Add(Params[i]);
                        }
                  }

                  SqlDataAdapter daSP=new SqlDataAdapter(cmdObj);
                  DataSet dsRes=new DataSet();

                  daSP.Fill(dsRes);
                  daSP.Dispose();

                  cmdObj.Dispose();
                  CloseConnection();

                  return dsRes;
            }
            ///
            /// <summary>
            /// Opens the connection to the database.
            /// </summary>
            protected static void OpenConnection()
            {
                  String strConnectionString=ConfigurationSettings.AppSettings["ConnectionString"];
                  Conn = new SqlConnection();
                  if (Conn.State==ConnectionState.Open)
                  {
                        Conn.Close();
                  }
                  else
                  {
                        Conn.ConnectionString=strConnectionString;
                        Conn.Open();
                  }
            }
            ///
            /// <summary>
            /// Closes the Connection
            /// </summary>
            protected static void CloseConnection()
            {
                  if (Conn!=null)
                  {
                        if (Conn.State==ConnectionState.Open)
                        {
                              Conn.Close();
                        }
                        Conn=null;
                  }
            }
0
 

Author Comment

by:BeginningWebDesign
ID: 12427505
Hi sukumar_diya

Tried code with datagrid and receive following error:

Parser Error Message: Could not load type 'DRDa.WebForm2'.

Source Error:


Line 1:  <%@ Page language="c#" Codebehind="WebForm2.cs" AutoEventWireup="false" Inherits="DRDa.WebForm2" %>
Line 2:  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
Line 3:  
 

Source File: C:\*****\test.aspx    Line: 1

Caz

0
 
LVL 7

Accepted Solution

by:
sukumar_diya earned 2000 total points
ID: 12430281
Hi Caz,
I am sorry. This is my mistake. i have copied all code i tried in my test project. DRDa is my test project.
and the webform2 is my form name. So you just copy the code from html tag paste in your form. Don't modify the <%page ...
in your form. that inherits your code behind to your HTML code.

in codebehind
change the namespace name as you want.
now it is like "namespace DRDa"  

public class WebForm2 : System.Web.UI.Page
in this change the webform2 with your form name...

Sukumar
0
 

Author Comment

by:BeginningWebDesign
ID: 12432155
Hi Sukumar

Still receive error

I have pasted header code and datagrid code, could you please take a look and change whatever needs changing.

Caz

<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="DRDa.WebForm2" %>

<form runat="server">
  <asp:DataGrid
  AllowCustomPaging="true"
  AllowPaging="true"
  AllowSorting="false"
  AutoGenerateColumns="false" BorderWidth="0"
  CellPadding="0"
  CellSpacing="0"
  id="QueryResults"
  PagerStyle-Mode="NextPrev"
  PagerStyle-NextPageText="Next --&gt;"
  PagerStyle-PrevPageText="&lt;-- Prev."
  runat="server"
  ShowFooter="true"
  ShowHeader="false"
 
  gridline="None"
>
    <HeaderStyle/>
    <ItemStyle CssClass="QuCssResults"/>
    <AlternatingItemStyle CssClass="QuCssResults"/>
    <FooterStyle/>
    <PagerStyle CssClass="QuCssResultsNav"/>
    <Columns>
         <asp:TemplateColumn  runat="server">
           <itemtemplate>
            <p><div style="float:right;"><span class="QuCssResultsRele">&nbsp;</span></div><br>
            <span class="QuCssResultsTitle">title</span><br>
            <span class="QuCssResultsBody"><%=HighlightWord%></span><br>
          <span class="QuCssResultsURL"><a href="url">url</a> </span></p><br>
       </itemtemplate></asp:TemplateColumn>
     </columns>
  </asp:DataGrid>
</form>


 public class [what goes here] : System.Web.UI.Page
0
 
LVL 7

Expert Comment

by:sukumar_diya
ID: 12432309
Hi caz,
Please follow this step...

1) Open a new form in your project and give a name for the form say now it is 'caz.aspx'.
2) go to the design and html code. paster the following code inside the <form id=...> paste it here </form>
 <asp:DataGrid
  AllowCustomPaging="true"
  AllowPaging="true"
  AllowSorting="false"
  AutoGenerateColumns="false" BorderWidth="0"
  CellPadding="0"
  CellSpacing="0"
  id="QueryResults"
  PagerStyle-Mode="NextPrev"
  PagerStyle-NextPageText="Next --&gt;"
  PagerStyle-PrevPageText="&lt;-- Prev."
  runat="server"
  ShowFooter="true"
  ShowHeader="false"
 
  gridline="None"
>
    <HeaderStyle/>
    <ItemStyle CssClass="QuCssResults"/>
    <AlternatingItemStyle CssClass="QuCssResults"/>
    <FooterStyle/>
    <PagerStyle CssClass="QuCssResultsNav"/>
    <Columns>
         <asp:TemplateColumn  runat="server">
           <itemtemplate>
            <p><div style="float:right;"><span class="QuCssResultsRele">&nbsp;</span></div><br>
            <span class="QuCssResultsTitle">title</span><br>
            <span class="QuCssResultsBody"><%=HighlightWord%></span><br>
          <span class="QuCssResultsURL"><a href="url">url</a> </span></p><br>
       </itemtemplate></asp:TemplateColumn>
     </columns>
  </asp:DataGrid>


3) go to the codebehind. Before the namespace u can see 'using' keyword for importing namespace.
replace all with the following
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

4)

u can see now
public class caz : System.Web.UI.Page
{
}

 in side this find the page_load function. Replace the whole function with the following code

 private void Page_Load(object sender, System.EventArgs e)
          {
               string SearchPhrase;    
               if( Request.QueryString["txtSearch"]!=null)
               {
                    SearchPhrase = Request.QueryString["txtSearch"];
                                                                DataTable dtTbl = searchfuntion(SearchPhrase,"");
                    datagrid.DataSource= dtTbl;
                    datagrid.DataBind();
               }
          }

          public DataTable searchfuntion(string param1,string param2)
          {
               SqlParameter[] colParams = new SqlParameter[2];
               try
               {
                    colParams[0] = new SqlParameter("@group_Name",param1);
                    colParams[1] = new SqlParameter("@group_Desc",param2);
                    return ExecuteSQL("usp_anchorage_group_master_insert",colParams);
               }
               catch(Exception ex)
               {
                    throw ex;
               }
          }    

          /// <summary>
          /// Executes the Stored Procedure with the SqlParameter array object passed
          /// and returns the DataSet
          /// </summary>
          /// <param name="CommandText"></param>
          /// <param name="Params"></param>
          /// <returns></returns>
          private static DataSet ExecuteSQL(String CommandText,SqlParameter[] Params)
          {
               OpenConnection();
               SqlCommand cmdObj=new SqlCommand();
               cmdObj.CommandType=CommandType.StoredProcedure;
               cmdObj.Connection=Conn;
               cmdObj.CommandText=CommandText;
               if (Params.Length>0)
               {
                    for (int i=0;i<Params.Length;i++)
                    {
                         cmdObj.Parameters.Add(Params[i]);
                    }
               }

               SqlDataAdapter daSP=new SqlDataAdapter(cmdObj);
               DataSet dsRes=new DataSet();

               daSP.Fill(dsRes);
               daSP.Dispose();

               cmdObj.Dispose();
               CloseConnection();

               return dsRes;
          }
          ///
          /// <summary>
          /// Opens the connection to the database.
          /// </summary>
          protected static void OpenConnection()
          {
               String strConnectionString=ConfigurationSettings.AppSettings["ConnectionString"];
               Conn = new SqlConnection();
               if (Conn.State==ConnectionState.Open)
               {
                    Conn.Close();
               }
               else
               {
                    Conn.ConnectionString=strConnectionString;
                    Conn.Open();
               }
          }
          ///
          /// <summary>
          /// Closes the Connection
          /// </summary>
          protected static void CloseConnection()
          {
               if (Conn!=null)
               {
                    if (Conn.State==ConnectionState.Open)
                    {
                         Conn.Close();
                    }
                    Conn=null;
               }
          }

hope it helps you..
sukumar
0
 

Author Comment

by:BeginningWebDesign
ID: 12439746
Hi sukumar_diya

I'll close this question down and award the points for all your help.

Regards
Caz
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question