如何使用数据集通过会话变量发送值 [英] How to send the values by session variables using Dataset
问题描述
如何使用数据集通过会话变量发送值....
这里我在一个存储过程中使用两个表
ALTER proc [dbo]。[SP_SessionByDataset]
@fname varchar(20),
@pwd varchar(20),
@Email varchar(30)
as
select * from reg其中fname = @fname和pwd = @ pwd
选择*来自tblPerson,其中Email = @ Email
GO
数据访问层,我有写得像这样...
公共DataSet SessionDataset(字符串FN,字符串PWD,字符串EMAIL)
{
con.Open();
cmd = new SqlCommand(SP_SessionByDataset,con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(@ fname,FN);
cmd.Parameters.AddWithValue(@ pwd,PWD);
cmd.Parameters。 AddWithValue(@ Email,EMAIL);
da = new S. qlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
con.Close();
返回ds;
}
在业务逻辑层,我写的是这样的...
public DataSet SessionDataset(字符串FN,字符串PWD,字符串EMAIL )
{
DataSet ds = d.SessionDataset(FN,PWD,EMAIL);
返回ds;
}
在应用层如何操作我使用DataSet完成任务...
在这里,我附加了由DataTable呈现的编码,用于其他一些编码......
同样,我必须使用数据集执行上述代码的任务...
protected void Btn_Login_Click(object sender,EventArgs e)
{
LblMessage.Visible = false;
试试
{
DAL d = new DAL();
DataTable dt = null;
DataSet ds = new DataSet();
// if(ds .Tables [0] .Rows [0] [fn]
dt = d.checkdata(txt_UName.Text.Trim(),txt_Pwd.Text.Trim ());
if(dt.Rows.Count> 0 && txt_Pwd.Text.ToString()== dt.Rows [0] [3] .ToString())
{
Session [CustomerId] = dt .Rows [0] [0] .ToString();
Session [CustomerName] = dt.Rows [0] [1] .ToString();
Session [MobileNo] = dt.Rows [0] [2] .ToString();
Session [UserType] = dt.Rows [0] [16] .ToString();
if(dt.Rows [0] [15] .ToString ()!=)
{
会话[CustomerTypeId] = dt.Rows [0] [15] .ToString();
}
其他
{
会话[CustomerTypeId] =会话[CustomerId]。ToString();
}
Session [FullName] = dt.Rows [0] [4] .ToString()++ dt.Rows [0] [5] .ToString ();
Response.Redirect(CascadingDDL.aspx,true);
}
else
{
LblMessage.Visible = true;
LblMessage.ForeColor = System.Drawing.Color.Red;
LblMessage.Text =无效登录证书;
}
}
catc h(例外情况)
{
LblMessage.Visible = true;
LblMessage.ForeColor = System.Drawing.Color.Red;
LblMessage.Text = ex.Message.ToString();
}
}
}
How to send the value by session variable using Dataset....
Here i am using two table in one stored procedure
ALTER proc [dbo].[SP_SessionByDataset]
@fname varchar(20),
@pwd varchar(20),
@Email varchar(30)
as
select *from reg where fname=@fname and pwd=@pwd
select *from tblPerson where Email=@Email
GO
in Data Access Layer, i have written like this...
public DataSet SessionDataset(string FN,string PWD,string EMAIL)
{
con.Open();
cmd = new SqlCommand("SP_SessionByDataset", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@fname",FN);
cmd.Parameters.AddWithValue("@pwd",PWD);
cmd.Parameters.AddWithValue("@Email",EMAIL);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
con.Close();
return ds;
}
In Business Logic Layer,i have written like this...
public DataSet SessionDataset(string FN, string PWD, string EMAIL)
{
DataSet ds = d.SessionDataset( FN,PWD,EMAIL);
return ds;
}
In Application Layer how to do i achieved the task by using DataSet...
Here i have attached the coding rendered by DataTable which is used in some other coding...
Likewise i have to do the task for above code by using Dataset...
protected void Btn_Login_Click(object sender, EventArgs e)
{
LblMessage.Visible = false;
try
{
DAL d = new DAL();
DataTable dt = null;
DataSet ds = new DataSet();
//if(ds.Tables[0].Rows[0]["fn"]
dt = d.checkdata(txt_UName.Text.Trim(),txt_Pwd.Text.Trim());
if (dt.Rows.Count > 0 && txt_Pwd.Text.ToString() == dt.Rows[0][3].ToString())
{
Session["CustomerId"] = dt.Rows[0][0].ToString();
Session["CustomerName"] = dt.Rows[0][1].ToString();
Session["MobileNo"] = dt.Rows[0][2].ToString();
Session["UserType"] = dt.Rows[0][16].ToString();
if (dt.Rows[0][15].ToString() != "")
{
Session["CustomerTypeId"] = dt.Rows[0][15].ToString();
}
else
{
Session["CustomerTypeId"] = Session["CustomerId"].ToString();
}
Session["FullName"] = dt.Rows[0][4].ToString() + " " + dt.Rows[0][5].ToString();
Response.Redirect("CascadingDDL.aspx", true);
}
else
{
LblMessage.Visible = true;
LblMessage.ForeColor = System.Drawing.Color.Red;
LblMessage.Text = "Invalid Login Credentials";
}
}
catch (Exception ex)
{
LblMessage.Visible = true;
LblMessage.ForeColor = System.Drawing.Color.Red;
LblMessage.Text = ex.Message.ToString();
}
}
}
推荐答案
学习好的一个
这篇关于如何使用数据集通过会话变量发送值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!