类1:
protected const string insertStr = "insert into {0}{1} select {2}";类2:
using System;
using System.Data;
namespace DataObject
{
/// <summary>
/// CommunityDataObject 的摘要说明。
/// </summary>
public class CommunityDataObject
{
public CommunityDataObject()
{
// TODO: 在此处添加构造函数逻辑
}
public string TableName = "Community";
private int _CommunityID;
private string _CommunityName;
private string _Re;
public virtual int CommunityID
{    
get{return _CommunityID;}
set{_CommunityID = value;}
}
public virtual string CommunityName
{    
get{return _CommunityName;}
set{_CommunityName = value;}
}
public virtual string Re
{    
get{return _Re;}
set{_Re = value;}
} }
}现在想获取"类2"中的字段:CommunityID,CommunityName,Re(CommunityID是主键自增字段)
并用"类1"中的SQL语句重新构造一条插入到表(Community)的SQL语句?请帮忙写出获取字段列表函数,和构造SQL的函数.谢谢.

解决方案 »

  1.   

    自增字段不要在insert所插入的字段中出现,例如:insert into community ( communityname, re ) select community, re from othertable
      

  2.   

    insert into community (CommunityID, communityname, re ) select CommunityID, communityname, re from othertable
    我想CommunityID是主键的话,就必须把CommunityID也插到表community,但表community 的CommunityID不能自增了
      

  3.   

    insert into community ( communityname, re ) select community, re from othertable