Adminfunctions.cs
using System;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
namespace prjstart
{
public class
adminfunctions // This class file is used to add
product categories,subcategories
{
public string addproductcategories(String
Categoryname)
{
SqlConnection
myconnection = new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
// Use the sqlcommand class to execute the stored
procedure.
SqlCommand
myCommand = new SqlCommand("addproductcategories",myconnection);
myCommand.CommandType
= CommandType.StoredProcedure;
// The SQLPARAMETER
class is used to fill the paramter with values.
SqlParameter
parametercategoryname = new
SqlParameter("@CategoryName",SqlDbType.NVarChar,50);
parametercategoryname.Value
= Categoryname;
myCommand.Parameters.Add(parametercategoryname);
SqlParameter
parametercategoryid = new
SqlParameter("@CategoryID",SqlDbType.NVarChar,50);
parametercategoryid.Direction
= ParameterDirection.Output;
myCommand.Parameters.Add(parametercategoryid);
// Here i am filling the two values required by the
underlying stored procedure.
try
{
myconnection.Open();
myCommand.ExecuteNonQuery();
myconnection.Close();
string categoryid =(string)parametercategoryid.Value;
return categoryid;
// This returns he category id which is the
output.
}
catch(Exception e)
{
return e.Message;
}
}
public string
addproductsubcategories(string Categoryid,string SubCategoryname)
{
SqlConnection
myconnection = new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand
myCommand = new
SqlCommand("addproductsubcategories",myconnection);
myCommand.CommandType
= CommandType.StoredProcedure;
SqlParameter
parametersubcategoryname = new
SqlParameter("@CategorySubName",SqlDbType.NVarChar,50);
parametersubcategoryname.Value
= SubCategoryname;
myCommand.Parameters.Add(parametersubcategoryname);
SqlParameter
parametercategoryid = new
SqlParameter("@CategoryID",SqlDbType.Int,50);
parametercategoryid.Value
= Categoryid;
myCommand.Parameters.Add(parametercategoryid);
SqlParameter
parameterinternalsubcategoryid = new
SqlParameter("@internalsubcategoryid",SqlDbType.NVarChar,50);
parameterinternalsubcategoryid.Direction
= ParameterDirection.Output;
myCommand.Parameters.Add(parameterinternalsubcategoryid);
try
{
myconnection.Open();
myCommand.ExecuteNonQuery();
myconnection.Close();
string subcategoryid =(string)parameterinternalsubcategoryid.Value;
return subcategoryid;
}
catch(Exception e)
{
return e.Message;
}
}
}
}