使用3层架构从数据库检索记录时出错? [英] errors while retrieving records from database using 3-tier architecture?

查看:100
本文介绍了使用3层架构从数据库检索记录时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码

code in DataAccessLayer

public DataSet FindRecord(int RollNumber)
      {

              using (SqlConnection con = new SqlConnection(cs))
              {
                  DataSet ds = new DataSet();
                  SqlCommand cmd = new SqlCommand("spfindtblstudent", con);
                  cmd.Parameters.AddWithValue("@RollNumber", RollNumber);
                  SqlDataAdapter da = new SqlDataAdapter(cmd);
                  cmd.CommandType = CommandType.StoredProcedure;
                  con.Open();
                  da.Fill(ds);
                  con.Close();
                  return ds;

              }
      }

业务逻辑层中的代码



Code in Business Logic Layer

public DataSet Find(int RollNumber)
       {
           DataSet ds = null;
           Dal objdal = new Dal();
           ds = objdal.FindRecord(RollNumber);

           return ds;
       }

Codebehind文件中的代码



Code in Codebehind File

protected void btnfind_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            int RollNumber = Convert.ToInt32(txtid.Text);
            Bll objbll = new Bll();
            objbll.Find(RollNumber);

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                txtname.Text = ds.Tables[0].Rows[0]["Name"].ToString();
                txtaddress.Text = ds.Tables[0].Rows[0]["Address"].ToString();
                txtphone.Text = ds.Tables[0].Rows[0]["Phone"].ToString();
            }
            else
            {
                Label1.Text = "No Record(s) avalilable";
            }

没有异常没有错误但没有检索到可能是什么问题?

no exception no error but not getting retrieved what could be the problem?

推荐答案

这不是我们的问题可以回答:它需要你的存储过程和你的数据库数据 - 我们也没有,也无法访问。



所以从在SSMS中测试你的SP:运行它,看看你得到了什么。

然后使用调试器来查看你传递给SP的确切内容作为RollNumber的值,并在继续之前确认它在SSMS中有效。

然后,准确地看一下数据集在调试器中获得了什么信息,然后查看调用C#方法的代码在返回时使用DataSet做什么。



但是我们做不到其中任何一个!
That isn't a question we can answer: it needs your stored procedure, and your database data - and we don't have either, and can't get access to either.

So start by testing your SP in SSMS: run it and see what you get.
Then use the debugger to look at exactly what you are passing to the SP as the value of RollNumber and confirm that works in SSMS before continuing.
Then, look at exactly what information the dataset got in the debugger before looking at what the code that called your C# method is doing with the DataSet when it's returned.

But we can't do any of that!


这篇关于使用3层架构从数据库检索记录时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆