In this article, GridView control as a movie screen layout like shown in below images in ASP.Net is explained
.
- First of all create database in SQL Server and name it as a "GridView_As_A_MOVIE_ScreenLayout" and in that database create the two tables like below.
- Create the stored procedures for adding screen, getting all screens, adding screen layout and getting screen layout.
/*(1st StoredProcedure)*//*This stored procedure is for adding screen which takes one parameter */Create Proc sp_AddScreen( @ScreenName varchar(20)) as Begin if not exists (select ScreenId from tbl_Screens where ScreenName = @ScreenName) begin insert into tbl_Screens(ScreenName) values (@ScreenName) end End
/*(2nd StoredProcedure)*//*This stored procedure is for getting all screens from tbl_Screens */Create procedure sp_GetScreens asselect * from tbl_Screens
/*(3rd StoredProcedure)*//*This stored procedure is for adding screen layout*/CREATE Procedure sp_AddScreenLayout(@RowName varchar(5),@ScreenId int,@1 varchar(5),@2 varchar(5),@3 varchar(5),@4 varchar(5),@5 varchar(5),@6 varchar(5),@7 varchar(5),@8 varchar(5),@9 varchar(5),@10 varchar(5),@11 varchar(5),@12 varchar(5),@13 varchar(5),@14 varchar(5),@15 varchar(5),@16 varchar(5),@17 varchar(5),@18 varchar(5),@19 varchar(5),@20 varchar(5),@21 varchar(5),@22 varchar(5),@23 varchar(5),@24 varchar(5),@25 varchar(5),@26 varchar(5),@27 varchar(5),@28 varchar(5),@29 varchar(5),@30 varchar(5),@Message varchar(150) out)AsBeginif @RowName = 'Line'begininsert into tbl_ScreenLayout (RowName,ScreenId,[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30]) values
@RowName,@ScreenId,@1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11,@12,@13,@14,@15,@16,@17,@18,@19,@20,@21,@22,@23,@24,@25,@26,@27,@28,@29,@30)set @Message = 'Added Successfully.'endelsebeginif (select ColumnId from tbl_ScreenLayout where RowName=@RowName and ScreenId=@ScreenId) is nullbegininsert into tbl_ScreenLayout (RowName,ScreenId,[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30]) values
@RowName,@ScreenId,@1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11,@12,@13,@14,@15,@16,@17,@18,@19,@20,@21,@22,@23,@24,@25,@26,@27,@28,@29,@30)set @Message = 'Added Successfully.'endendEnd
/*(4th StoredProcedure)*//*This stored procedure is to get screen layout */CREATE procedure sp_GetScreenLayout(@ScreenId int) asselect * from tbl_Screens s inner join tbl_ScreenLayout sl on sl.ScreenId=s.ScreenId and sl.ScreenId=@ScreenId
- In Web.config file write a connection string in <connectionStrings/> tag.
<connectionStrings> <add name="constr" connectionString="User Id = sa; Password = 123; Database = GridView_As_A_MOVIE_ScreenLayout; Data Source= KatareRaju"/> </connectionStrings>
- Add New Class by right clicking on solution explorer and name it as a DAL (DAL = Data Access Layer) and define three methods like follows.
static SqlConnection con; static SqlCommand cmd; static DataSet ds; static SqlDataAdapter da; /*(1st method in DAL.cs)*/ /*GetConnectionString method reads the connection string from web.config file and returns connection string*/ public static string GetConnectionString() { return ConfigurationManager.ConnectionStrings["constr"].ConnectionString; } /*(2nd method in DAL.cs)*/ /*This method is for performing operations like Insert, Update and Delete*/ public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText, SqlParameter[] parameters) { try { con = new SqlConnection(connectionString); cmd = new SqlCommand(commandText, con); cmd.CommandType = commandType; foreach (SqlParameter p in parameters) { if (p.Value == null) { } cmd.Parameters.Add(p); } con.Open(); return cmd.ExecuteNonQuery(); } catch (SqlException ex) { throw new ArgumentException(ex.Message); } finally { con.Close(); } } /*(3rd method in DAL.cs)*/ /*This method is for retrieving data from database*/ public static DataSet ExecuteDataSet(string connectionString, CommandType commandType, string commandText, SqlParameter[] parameters) { try { con = new SqlConnection(connectionString); cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = commandText; cmd.CommandType = commandType; if (parameters == null) { da = new SqlDataAdapter(cmd); ds = new DataSet(); da.Fill(ds); return ds; } else { foreach (SqlParameter p in parameters) { if ((p.Direction == ParameterDirection.InputOutput) && (p.Value == null)) { } //if (p.Value != null) //{ cmd.Parameters.Add(p); //} } da = new SqlDataAdapter(cmd); ds = new DataSet(); da.Fill(ds); return ds; } } catch (SqlException ex) { throw new ArgumentException(ex.Message); } }
READ MORE >>
0 comments:
Post a Comment