system.data.dll中出现'system.invalidoperationexception'类型的例外 [英] An exception of type 'system.invalidoperationexception' occurred in system.data.dll
本文介绍了system.data.dll中出现'system.invalidoperationexception'类型的例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
An exception of type 'System.InvalidOperationException' occurred in System.Data.dll
我尝试了什么:
What I have tried:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.SqlClient;
using WebApplication3.Models;
namespace WebApplication3.Controllers
{
public class ProductController : Controller
{
String cs = @"Data Source = DESIGNER\\SQLEXPRESS; Initial Catalog = MvcCrudDB; Integrated Security = True";
[HttpGet]
public ActionResult Index()
{
DataTable dtblProduct = new DataTable();
using (SqlConnection con = new SqlConnection(cs))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT*FROM Product",con);
da.Fill(dtblProduct);
con.Close();
}
return View(dtblProduct);
}
推荐答案
基于 DbDataAdapter.Fill Method(DataTable)(System.Data.Common) [ ^ ]如果源表无效,则抛出异常。
所以很可能你没有在数据库中有一个名为Product
的表MvcCrudDB
或者它可能在dbo
之外的其他模式中。
Based on DbDataAdapter.Fill Method (DataTable) (System.Data.Common)[^] that exception is thrown if the source table is invalid.
So the chances are you don't have a table namedProduct
in databaseMvcCrudDB
or perhaps it's in another schema thandbo
.
这篇关于system.data.dll中出现'system.invalidoperationexception'类型的例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文