public int InsertNewDrug(DATA data)
{
string sql1 = @"INSERT INTO TABLE (";
string sql2 = @") VALUES (";
string sql3 = @")";
IDictionary dic = new Hashtable();
foreach (var prop in date.GetType().GetProperties())//获取数据名称
{
if (prop.Name == "Date")
{
if (Convert.ToDateTime(prop.GetValue(data, null)) != DateTime.MinValue)
{
sql1 += prop.Name + ",";
sql2 += "'" + prop.GetValue(data, null) + "',";//获取数据值
}
}
else
{
sql1 += prop.Name + ",";
sql2 += "'" + prop.GetValue(data, null) + "',";
}
}
string sql = sql1.Substring(0, sql1.Length - 1) + sql2.Substring(0, sql2.Length - 1)+sql3;
return base.ExecuteNonQuery(sql, dic);
}