日期:2014-05-20  浏览次数:20709 次

SqlDataAdapter.Fill不能填充数据
源代码如下:希望大家帮我看看
SqlDataAdapter   da;
string   choice,chString;
SqlConnection   con   =   new   SqlConnection(ConfigurationSettings.AppSettings[ "Conn "]);
DataSet   ds   =   new   DataSet();

private   void   Page_Load(object   sender,   System.EventArgs   e)
{
if(!Page.IsPostBack)
{
choice   =   Request.QueryString[ "Choice "].ToString();
if(choice.Length   >   0)
{
Response.Clear();
string   ooo   =   string.Format( "select   *   from   area   where   city   =   {0} ",choice);
if(choice   ==   "All   cities ")
da   =   new   SqlDataAdapter( "select   *   from   area ",con);
else
da   =   new   SqlDataAdapter(ooo,   con);
da.Fill(ds, "area ");
ds.Tables[0].TableName   =   "area ";
chString   =   ds.GetXml();
}
else
{
Response.Write(chString);
Response.End();
}
}

------------------------------------

运行到da.Fill(ds, "area ");这一句时运行不下去了
大家帮我看看
谢谢

------解决方案--------------------
两个可能
1. 数据库没连接上
2. sql语句错误
------解决方案--------------------
SqlDataAdapter 的 SqlCommand 的 字符串拿出来在SQLServer 里执行一下,看有没有结果。
------解决方案--------------------
da.Fill(ds, "area "); ?????
da.Fill(ds.area);
------解决方案--------------------
你把SqlDataAdapter da;
string choice,chString;
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings[ "Conn "]);
DataSet ds = new DataSet();
放在外面他怎么能找到da.Fill(ds, "area ");这里面的ds呢/
把他们放在函数里面.

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
SqlDataAdapter da;
string choice,chString;
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings[ "Conn "]);
DataSet ds = new DataSet();
choice = Request.QueryString[ "Choice "].ToString();
if(choice.Length > 0)
{
Response.Clear();
string ooo = string.Format( "select * from area where city = {0} ",choice);
if(choice == "All cities ")
da = new SqlDataAdapter( "select * from area ",con);
else
da = new SqlDataAdapter(ooo, con);
da.Fill(ds, "area ");
ds.Tables[0].TableName = "area ";
chString = ds.GetXml();
}
else
{
Response.Write(chString);
Response.End();
}
}
再试试