TreeHierarchy.aspx
DirectoryInfo newDirectory = new DirectoryInfo(appPath + txtName.Text);
BAL obj1 = new BAL();
DataTable dt = new DataTable();
SqlParameter []p =new SqlParameter[1];
p[0]=new SqlParameter("@FName",txtName.Text);
string chk= obj1.ExecuteScaler("SP_CreateFolder", p);
if (!newDirectory.Exists)
{
newDirectory.Create();
}
else if (chk == "1")
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('Already Exists');</script>");
}
BAL.cs
public string ExecuteScaler(string strtbl,SqlParameter [] p)
{
return DAL.ExecuteScaler(strtbl, p);
}
{
return DAL.ExecuteScaler(strtbl, p);
}
DAL.cs
{
SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Interview\N-Tier\PropertyLayer\App_Data\Main.mdf;Integrated Security=True;User Instance=True");
try
{
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = cn;
cmd.CommandText = SP;
cmd.Parameters.AddRange(p);
string str = cmd.ExecuteScalar().ToString();
return str;
}
catch (Exception ex)
{
throw ex;
}
}
Stored Procedure
ALTER PROCEDURE dbo.SP_CreateFolder
@FName varchar(100)
AS
begin
if exists(select FolderName from Main where FolderName=@FName)
begin
select 1
End
else
begin
insert into Main (FolderName,CreatedDate,CreatedEmpId)
values(@FName,getdate(),1)
eNd
eNd
No comments:
Post a Comment