本文整理汇总了C#中DataTier.Data.getSize方法的典型用法代码示例。如果您正苦于以下问题:C# Data.getSize方法的具体用法?C# Data.getSize怎么用?C# Data.getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataTier.Data
的用法示例。
在下文中一共展示了Data.getSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: updateSP
//update, insert and delete data in database using stored procedure
public int updateSP(String spName, Data data)
{
cmd = null;
int result = 0;
try
{
tran = conn.BeginTransaction();
cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = spName;
cmd.Connection = conn;
cmd.Transaction = tran;
String key = null;
SqlDbType sType = SqlDbType.NVarChar;
int size = -1;
Object[] keys = data.getKeys();
Object value = null;
int length = keys.Length;
//add parameters using keys
if (keys != null)
{
for (int i = 0; i < length; i++)
{
key = "@" + keys[i].ToString();
value = data.get(keys[i]);
size = data.getSize(key);
sType = data.getType(key);
if (size > 0)
{
cmd.Parameters.Add(key, sType);
}
else
{
cmd.Parameters.Add(key, sType, size);
}
cmd.Parameters[key].Value = value;
}
}
result = cmd.ExecuteNonQuery();
tran.Commit();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
//Trace. (e.Message);
tran.Rollback();
}
finally
{
if (cmd != null)
{
cmd.Parameters.Clear();
}
}
return result;
}
示例2: selectSP
//select data from database using stored procedure
public Data selectSP(String spName, Data data)
{
cmd = null;
Data result = new Data();
try
{
cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = spName;
cmd.Connection = conn;
String key = null;
SqlDbType sType = SqlDbType.NVarChar;
int size = -1;
Object[] keys = data.getKeys();
Object value = null;
int now = 0;
//add parameters using keys
if (keys != null)
{
int length = keys.Length;
for (int i = 0; i < length; i++)
{
key = "@" + keys[i].ToString();
value = data.get(keys[i]);
size = data.getSize(key);
sType = data.getType(key);
if (size > 0)
{
cmd.Parameters.Add(key, sType);
}
else
{
cmd.Parameters.Add(key, sType, size);
}
cmd.Parameters[key].Value = value;
}
}
// get query results
rdr = cmd.ExecuteReader();
//save result into Data
while (rdr.Read())
{
int fCount = rdr.FieldCount;
for (int i = 0; i < fCount; i++)
{
result.add(now, rdr.GetName(i), rdr.GetValue(i));
}
++now;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
result.ErrorMessage = e.Message;
}
finally
{
if (cmd != null)
{
cmd.Parameters.Clear();
}
// close the reader
if (rdr != null)
{
rdr.Close();
}
}
return result;
}