ASP.NET中关于dataset的问题 10
以下是我的程序:usingSystem;usingSystem.Collections;usingSystem.Configuration;usingSystem.Dat...
以下是我的程序:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class dataadpater : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet set=UseDataadpater();
}
public DataSet UseDataadpater()
{
SqlConnection myCon=new SqlConnection();
myCon.ConnectionString="Persist Security info=false; User id=sa;pwd=wxz;database=northwind;server=PC-200909061709";
myCon.Open();
SqlDataAdapter myAdpater=new SqlDataAdapter();
SqlCommand myCom=new SqlCommand();
myCom.Connection=myCon;
myCom.CommandText="select CustomerID,CompanyName from Customers";
myAdpater.SelectCommand=myCom;
DataSet mySet=new DataSet();
myAdpater.Fill(mySet,"Customers");
SqlCommand updata=new SqlCommand();
updata.Connection=myCon;
updata.CommandText = "update Customers set CompanyName='KFC' where CustomerID='ALFKI'";
myAdpater.UpdateCommand=updata;
myAdpater.Update(mySet);
myCon.Close();
return mySet;
}
protected void Button1_Click(object sender, EventArgs e)
{
Look();
}
public void Look()
{
DataSet newSet = UseDataadpater();
string str = "";
str = "<table border=1>";
for (int i = 0; i < newSet.Tables[0].Rows.Count; i++)
{
str = str + "<tr>";
for (int j = 0; j < newSet.Tables[0].Columns.Count; j++)
{
str = str + "<td>" + newSet.Tables[0].Rows[i].ItemArray[j] + "</td>";
}
str = str + "</tr>";
}
str = str + "</table>";
Label1.Text = str;
Response.Write(newSet.Tables[0].TableName);
}
}
运行后出现:Update 无法找到 TableMapping['Table'] 或 DataTable“Table”........
我在fill里已经指明此表叫Customers了 为什么在update的时候却找不到此表呢? 展开
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class dataadpater : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet set=UseDataadpater();
}
public DataSet UseDataadpater()
{
SqlConnection myCon=new SqlConnection();
myCon.ConnectionString="Persist Security info=false; User id=sa;pwd=wxz;database=northwind;server=PC-200909061709";
myCon.Open();
SqlDataAdapter myAdpater=new SqlDataAdapter();
SqlCommand myCom=new SqlCommand();
myCom.Connection=myCon;
myCom.CommandText="select CustomerID,CompanyName from Customers";
myAdpater.SelectCommand=myCom;
DataSet mySet=new DataSet();
myAdpater.Fill(mySet,"Customers");
SqlCommand updata=new SqlCommand();
updata.Connection=myCon;
updata.CommandText = "update Customers set CompanyName='KFC' where CustomerID='ALFKI'";
myAdpater.UpdateCommand=updata;
myAdpater.Update(mySet);
myCon.Close();
return mySet;
}
protected void Button1_Click(object sender, EventArgs e)
{
Look();
}
public void Look()
{
DataSet newSet = UseDataadpater();
string str = "";
str = "<table border=1>";
for (int i = 0; i < newSet.Tables[0].Rows.Count; i++)
{
str = str + "<tr>";
for (int j = 0; j < newSet.Tables[0].Columns.Count; j++)
{
str = str + "<td>" + newSet.Tables[0].Rows[i].ItemArray[j] + "</td>";
}
str = str + "</tr>";
}
str = str + "</table>";
Label1.Text = str;
Response.Write(newSet.Tables[0].TableName);
}
}
运行后出现:Update 无法找到 TableMapping['Table'] 或 DataTable“Table”........
我在fill里已经指明此表叫Customers了 为什么在update的时候却找不到此表呢? 展开
1个回答
展开全部
去这个blog看看吧
http://hi.baidu.com/fgmis
http://hi.baidu.com/fgmis
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询