本文整理汇总了C#中IDataParameter.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# IDataParameter.SetValue方法的具体用法?C# IDataParameter.SetValue怎么用?C# IDataParameter.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataParameter
的用法示例。
在下文中一共展示了IDataParameter.SetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateObj2Table
public int UpdateObj2Table(object obj, string strTableName, string strWhere)
{
string sql = "select * from " + strTableName + " where 1!=1";
DataSet ds = this.ExecuteDataset(sql);
Type myType = obj.GetType();
System.Reflection.PropertyInfo[] pInfos = myType.GetProperties();
StringBuilder strKey = new StringBuilder();
int count = 0;
for (int i = 0; i < pInfos.Length; i++)
{
System.Reflection.PropertyInfo pPropertyInfo = pInfos[i];
if (ds.Tables[0].Columns.Contains(pPropertyInfo.Name))
{
count++;
}
}
IDataParameter[] parameterValues = new IDataParameter[count];
count = 0;
for (int i = 0; i < pInfos.Length; i++)
{
System.Reflection.PropertyInfo pPropertyInfo = pInfos[i];
if (ds.Tables[0].Columns.Contains(pPropertyInfo.Name))
{
strKey.Append("," + pPropertyInfo.Name + "=:x" + pPropertyInfo.Name);
parameterValues.SetValue(this.GetParameter(":x" + pPropertyInfo.Name, pPropertyInfo.GetValue(obj, null)), count);
count++;
}
}
string strSql = "update " + strTableName + " set " + strKey.ToString().Remove(0, 1) + " where " + strWhere;
return this.ExecuteNonQuery(strSql, parameterValues);
}
示例2: InsertObj2Table
public int InsertObj2Table(object obj, string strTableName)
{
string sql = "select * from " + strTableName + " where 1!=1";
DataSet ds = this.ExecuteDataset(sql);
Type myType = obj.GetType();
System.Reflection.PropertyInfo[] pInfos = myType.GetProperties();
StringBuilder strKey = new StringBuilder();
StringBuilder strValue = new StringBuilder();
int count = 0;
for (int i = 0; i < pInfos.Length; i++)
{
System.Reflection.PropertyInfo pPropertyInfo = pInfos[i];
if (ds.Tables[0].Columns.Contains(pPropertyInfo.Name))
{
count++;
}
}
IDataParameter[] parameterValues = new IDataParameter[count];
count = 0;
for (int i = 0; i < pInfos.Length; i++)
{
System.Reflection.PropertyInfo pPropertyInfo = pInfos[i];
if (ds.Tables[0].Columns.Contains(pPropertyInfo.Name))
{
strKey.Append("," + pPropertyInfo.Name);
strValue.Append(",:x" + pPropertyInfo.Name);
string typename = pPropertyInfo.PropertyType.FullName;
if (typename == "System.Byte[]")
{
byte[] bytes = pPropertyInfo.GetValue(obj, null) as byte[];
if (bytes == null || bytes.Length == 0)
{
parameterValues.SetValue(this.GetParameter(":x" + pPropertyInfo.Name, DBNull.Value), count);
}
else
{
parameterValues.SetValue(this.GetParameter(":x" + pPropertyInfo.Name, pPropertyInfo.GetValue(obj, null)), count);
}
}
else
{
parameterValues.SetValue(this.GetParameter(":x" + pPropertyInfo.Name, pPropertyInfo.GetValue(obj, null)), count);
}
count++;
}
}
string strSql = "insert into " + strTableName + " (" + strKey.ToString().Remove(0, 1) + ") values(" + strValue.ToString().Remove(0, 1) + ")";
return this.ExecuteNonQuery(strSql, parameterValues);
}