(C# ASP.NET) sda.Fill(ds);莫名其妙的出错,不可理喻
前台只是添加了一个GridView控件<div><asp:GridViewID="GridView1"runat="server"BackColor="White"Bor...
前台只是添加了一个GridView 控件
<div>
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">
<FooterStyle BackColor="Black" />
</asp:GridView>
</div>
后台主要代码:
using System.Data.SqlClient;
public partial class ADO : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
string myconn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Test_t_client"].ToString();
conn.ConnectionString = myconn;
conn.Open();
String strSQL = "select * from t_client";
SqlDataAdapter sda = new SqlDataAdapter(strSQL, conn);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
调试后,这行 代码:sda.Fill(ds);出现,错误提示:Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately
Compiler Error Message: CS1502: The best overloaded method match for 'System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)' has some invalid arguments
哪位帮忙修改下 展开
<div>
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">
<FooterStyle BackColor="Black" />
</asp:GridView>
</div>
后台主要代码:
using System.Data.SqlClient;
public partial class ADO : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
string myconn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Test_t_client"].ToString();
conn.ConnectionString = myconn;
conn.Open();
String strSQL = "select * from t_client";
SqlDataAdapter sda = new SqlDataAdapter(strSQL, conn);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
调试后,这行 代码:sda.Fill(ds);出现,错误提示:Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately
Compiler Error Message: CS1502: The best overloaded method match for 'System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)' has some invalid arguments
哪位帮忙修改下 展开
展开全部
你这个问题很奇怪,按说是可以正常运行的。但通过错误信息我们可以看出,Fill方法的参数需要的类型为DataTable类型。你写的代码中传递的是一个DataSet ,SqlDataAdapter 的fill方法按说是应该可以接收Dataset类型的参数。但错误信息显示你调用并非是SqlDataAdapter的Fill方法,而是DbDataAdater的Fill方法,并且该Fill方法的参数只允许接收DataTable类型。那你现阶段的话,只能将DataSet 改成DataTable 了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询