找不到表0,systemINdexOutOfrange异常 [英] cannot find table 0,systemINdexOutOfrange Exception

查看:212
本文介绍了找不到表0,systemINdexOutOfrange异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用存储过程从数据库中检索数据,但我无法检索,它的告知错误找不到表0.我的代码是

Hi,
I am trying to retrieve data from database using stored procedure , but i am not able retrieve ,its telling error cannot find table 0.My code is

public List<userprofile> GetQualification()
      {


          List<userprofile> UserPRofileDc = new List<userprofile>();
          string CS="data source='DIVYA-PC\SQL2012';database=SchoolManagement;User=scsdesk; Password=scs@123;";
          //string CS = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
          using (SqlConnection con = new SqlConnection(CS))
          {
              con.Open();
              SqlCommand cmd = new SqlCommand("GetQualification", con);
              cmd.CommandType = CommandType.StoredProcedure;
              DataSet ds = new DataSet();
              SqlDataAdapter da = new SqlDataAdapter(cmd);
              cmd.ExecuteNonQuery();
              da.Fill(ds);
              if ( ds!=null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
              {

                  foreach (DataRow drow in ds.Tables[0].Rows)
                  {
                      UserProfile user = new UserProfile();
                      user.FatherQualification = Convert.ToString(drow["Name"]);
                      user.pkFatherQualificationId = Convert.ToInt32(drow["pkQualificationId"]);
                      UserPRofileDc.Add(user);

                  }
              }


                  return UserPRofileDc;

          }
      }



控制器:


controller:

public ActionResult StudentProfile()
       {

           Elite.DAL.Admin admin = new Elite.DAL.Admin();
           List<UserProfile> Qualification = admin.GetQualification();

           return View(Qualification);
       }

推荐答案

看我打破你的状况

See i am breaking your condition
if ( ds!=null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)

to

to

if ( ds!=null && ds.Tables.Count > 0 )  if(ds.Tables[0].Rows.Count > 0) {
 
                   foreach (DataRow drow in ds.Tables[0].Rows)
                   {  
                       UserProfile user = new UserProfile();
                       user.FatherQualification = Convert.ToString(drow["Name"]);
                       user.pkFatherQualificationId = Convert.ToInt32(drow["pkQualificationId"]);
                       UserPRofileDc.Add(user);
 
                   }
               }


这篇关于找不到表0,systemINdexOutOfrange异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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