本文整理汇总了C#中System.Data.SqlClient.SqlParameter.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# SqlParameter.GetLength方法的具体用法?C# SqlParameter.GetLength怎么用?C# SqlParameter.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlParameter
的用法示例。
在下文中一共展示了SqlParameter.GetLength方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddSQLParameters
public void AddSQLParameters(SqlCommand sqlcmd, SqlParameter[] sqlParam)
{
for (int i = 0; i < sqlParam.GetLength(0); i++)
{
sqlcmd.Parameters.Add(sqlParam[i]);
}
}
示例2: AddSQLParameters
public void AddSQLParameters(SqlCommand sqlcmd, SqlParameter[] sqlParam)
{
for (int i = 0; i < sqlParam.GetLength(0); i++)
{
if (sqlParam[i] == null)
break;
sqlcmd.Parameters.Add(sqlParam[i]);
sqlcmd.Parameters[i].Direction = sqlParam[i].Direction;
if (sqlParam[i].Value != "")
Framework.Utilities.DebugLogging.Log("SQL PARAM " + i + " : " + sqlParam[i] + " " + sqlParam[i].Value);
}
}
示例3: transObjToParams
private SqlParameter[] transObjToParams(string[] str, Object[] obj)
{
SqlParameter[] param = new SqlParameter[obj.GetLength(0)];
for (int i = 0; i < param.GetLength(0); i++) {
if (obj[i] is Int32) {
param[i] = new SqlParameter("?" + str[i], SqlDbType.Int);
param[i].Value = Convert.ToInt32(obj[i]);
}
else if (obj[i] is Double) {
param[i] = new SqlParameter("?" + str[i], SqlDbType.Float);
param[i].Value = Convert.ToDouble(obj[i]);
}
else {
try {
Convert.ToDateTime(obj[i]);
param[i] = new SqlParameter("?" + str[i], SqlDbType.DateTime);
param[i].Value = Convert.ToString(obj[i]);
}
catch {
param[i] = new SqlParameter("?" + str[i], SqlDbType.VarChar);
param[i].Value = Convert.ToString(obj[i]);
}
}
}
return param;
}
示例4: CopyReader
// Needs reader to be positioned on the first row
private static void CopyReader(SqlDataReader reader, SqlConnection outCon,
string outTable, SqlParameter[] paramList)
{
using (SqlCommand outCmd = outCon.CreateCommand())
try {
System.Text.StringBuilder insertCmdStr =
new System.Text.StringBuilder();
insertCmdStr.AppendFormat("INSERT INTO {0} VALUES (", outTable);
for (int i = 0; i < paramList.GetLength(0); i++) {
if (i > 0)
insertCmdStr.Append(", ");
insertCmdStr.AppendFormat("@col{0}", i);
outCmd.Parameters.Add(paramList[i]);
}
insertCmdStr.Append(")");
outCmd.CommandText = insertCmdStr.ToString();
// If this throws, the most likely culprit is one (or more) of the
// SqlParameters being generated incorrectly in GenerateSchema()
outCmd.Prepare();
do {
for (int i = 0; i < paramList.GetLength(0); i++) {
paramList[i].SqlValue = reader.GetSqlValue(i);
}
outCmd.ExecuteNonQuery();
if (sendDebugInfo)
SqlContext.Pipe.Send(string.Format("Record sent to {0}",
outTable));
} while (reader.Read());
outCmd.Parameters.Clear();
} catch (SqlException e) {
throw new System.Exception(
string.Format("Could not send data to {0}", outTable), e);
}
}