“Rollnumber”这个名字在目前的背景下是不存在的?为什么? [英] the name 'Rollnumber' does't exist in the current context? why?

查看:144
本文介绍了“Rollnumber”这个名字在目前的背景下是不存在的?为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

bll中的代码



code in bll

public DataSet Find(String str)
       {
           if (str == "")
               throw new Exception("Please provide ID to search");

           DataSet ds = null;
           Dal objdal = new Dal();
           ds = objdal.FindRecord(RollNumber);

           return ds;
       }





dal代码





code in dal

public DataSet FindRecord(int RollNumber)
        {
            DataSet ds = null;
            try
            {
                string command = "Select * from tblstudent where RollNumber=@RollNumber";
                using (SqlConnection con = new SqlConnection(cs))
                {
                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter("command", con);
                    
                    ds = new DataSet();
                    da.Fill(ds, "tblstudent");
                    con.Close();
                    
                }
            }
            catch (Exception e)
            {
                string st = e.Message;
                
            }
            return ds;
       }



我已经添加了引用以及它为什么会出现此错误?请事先知道谢谢


i have added the references as well why it's giving this error? Please let me know thanks in advance

推荐答案

看来你需要根据输入str进行搜索,但是你的方法需要整数值并且没有定义RollNumber。尝试下面(假设您有数字作为输入str)



it seems you need to search based on input str, but your method expect integer value and that RollNumber is not defined. try below ( assume you have numbers as input str)

int RollNumber = Convert.ToInt32(str);
ds = objdal.FindRecord(RollNumber);


Public DataSet FindRecord(int RollNumber)
{
try{
string command="select * from tblstudent Where rollnumber=@ROLLNUMBER";
using(sqlcommand cmd=new sqlcommand(command,con){
cmd.parameters.add("@ROLLNUMBER", SqlDbType.Int32)=ROLLNUMBER;
sqldataadapter da=new sqldataadapter(cmd);
dataset ds=new dataset();
da.fill(ds);
return ds;
}
}
}


这篇关于“Rollnumber”这个名字在目前的背景下是不存在的?为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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