ASP.NET objectDatasource的问题
asp.netGrideView+ObjectDataSource前台:<asp:ObjectDataSourceselectmethod="GetProduct"Typ...
asp.net GrideView + ObjectDataSource
前台:
<asp:ObjectDataSource selectmethod="GetProduct" Type="Product" UpdateMethod="Update_Product" id="objectdatasource1"/>
Product.cs:
public class product
{
public static SqlDataReader GetProduct()
{
SqlConnection con = new SqlConnection(@"Server=local;Integrated Security=True;" + "Database=DB");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "get_product";
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
public void Update_Product(int ProductID,string Name,string Description,string Price)
{
SqlConnection con = new SqlConnection(@"Server=local;Integrated Security=True;" + "Database=DB");
string updateString = "UPDATE Product SET Name=@Name,Description=@Description,Price=@Price WHERE ProductID=@ProductID";
SqlCommand cmd = new SqlCommand(updateString, con);
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Parameters.AddWithValue("@Description", Description);
cmd.Parameters.AddWithValue("@Price",Price);
cmd.Parameters.AddWithValue("@ProductID",ProductID);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
更新数据的时候没办法输入数据,要是不该表数据直接点更新后,报错:objectDataSource1 未能找到带参数的非泛型方法
Update_Product:ProductID
什么原因?? 展开
前台:
<asp:ObjectDataSource selectmethod="GetProduct" Type="Product" UpdateMethod="Update_Product" id="objectdatasource1"/>
Product.cs:
public class product
{
public static SqlDataReader GetProduct()
{
SqlConnection con = new SqlConnection(@"Server=local;Integrated Security=True;" + "Database=DB");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "get_product";
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
public void Update_Product(int ProductID,string Name,string Description,string Price)
{
SqlConnection con = new SqlConnection(@"Server=local;Integrated Security=True;" + "Database=DB");
string updateString = "UPDATE Product SET Name=@Name,Description=@Description,Price=@Price WHERE ProductID=@ProductID";
SqlCommand cmd = new SqlCommand(updateString, con);
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Parameters.AddWithValue("@Description", Description);
cmd.Parameters.AddWithValue("@Price",Price);
cmd.Parameters.AddWithValue("@ProductID",ProductID);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
更新数据的时候没办法输入数据,要是不该表数据直接点更新后,报错:objectDataSource1 未能找到带参数的非泛型方法
Update_Product:ProductID
什么原因?? 展开
2个回答
展开全部
public void Update_Product(int ProductID,string Name,string Description,string Price)
{
SqlConnection con = new SqlConnection(@"Server=local;Integrated Security=True;" + "Database=DB");
string updateString = "UPDATE Product SET Name=@Name,Description=@Description,Price=@Price WHERE ProductID=@ProductID";
SqlCommand cmd = new SqlCommand(updateString, con);
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Parameters.AddWithValue("@Description", Description);
cmd.Parameters.AddWithValue("@Price",Price);
cmd.Parameters.AddWithValue("@ProductID",ProductID);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
里面的“@ProductID”数据库类型是否相同
{
SqlConnection con = new SqlConnection(@"Server=local;Integrated Security=True;" + "Database=DB");
string updateString = "UPDATE Product SET Name=@Name,Description=@Description,Price=@Price WHERE ProductID=@ProductID";
SqlCommand cmd = new SqlCommand(updateString, con);
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Parameters.AddWithValue("@Description", Description);
cmd.Parameters.AddWithValue("@Price",Price);
cmd.Parameters.AddWithValue("@ProductID",ProductID);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
里面的“@ProductID”数据库类型是否相同
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询