Click here to Skip to main content
15,886,110 members
Articles / Web Development / ASP.NET

Gridview inside Gridview in ASP.NET C#

Rate me:
Please Sign up or sign in to vote.
4.78/5 (19 votes)
9 Jun 2011CPOL1 min read 194.1K   8.4K   42  
Gridview inside Gridview in ASP.NET C# or Nested Gridview and Update, Delete from Gridview
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
	public Class1()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public static DataSet fillDataset(string sql)
    {
        SqlConnection Scon = new SqlConnection(ConfigurationManager.ConnectionStrings["CS"].ToString());
        SqlCommand Scmd = new SqlCommand(sql, Scon);
        Scmd.CommandType = CommandType.Text;
        SqlDataAdapter adp = new SqlDataAdapter(Scmd);
        DataSet ds = new DataSet();
        try
        {
            if (Scon.State == ConnectionState.Closed)
            {
                Scon.Open();
                adp.Fill(ds);

            }
        }
        catch
        {
        }
        finally
        {
            adp.Dispose();
            if (Scon.State == ConnectionState.Open)
            {
                Scon.Close();
            }
        }
        
        return ds;
    }
    public static int nonquery(string sql)
    {
        SqlConnection Scon = new SqlConnection(ConfigurationManager.ConnectionStrings["CS"].ToString());
        SqlCommand Scmd = new SqlCommand(sql, Scon);
        Scmd.CommandType = CommandType.Text;

        int rowsaffected = 0;
        try
        {
            if (Scon.State == ConnectionState.Closed)
            {
                Scon.Open();

                rowsaffected = Scmd.ExecuteNonQuery();
            }
        }
        catch
        {
        }
        finally
        {
        }
        return rowsaffected;
    }

    public static int nonquery1(string Id, string name)
    {
        SqlConnection Scon = new SqlConnection(ConfigurationManager.ConnectionStrings["CS"].ToString());
        SqlCommand Scmd = new SqlCommand("spUpdate", Scon);
        Scmd.CommandType = CommandType.StoredProcedure;
        Scmd.Parameters.Add("@FName", SqlDbType.VarChar).Value = name;
        Scmd.Parameters.Add("@ID", SqlDbType.BigInt).Value = long.Parse(Id);
        int rowsaffected = 0;
        try
        {
            if (Scon.State == ConnectionState.Closed)
            {
                Scon.Open();

                rowsaffected = Scmd.ExecuteNonQuery();
            }
        }
        catch
        {
        }
        finally
        {
        }
        return rowsaffected;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer India
India India
http://devcorners.com/
Total DotNet/Programming Solution

I am Prasanta Banerjee. I am an Asp.Net Developer. My site: http://devcorners.com/
Email: prasanta.it@hotmail.com
If any body wants to prepare for interview http://guru-code.blogspot.com/ is the good site.

Comments and Discussions