本文整理汇总了C#中System.Data.SqlTypes.SqlInt16.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# SqlInt16.ToString方法的具体用法?C# SqlInt16.ToString怎么用?C# SqlInt16.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlTypes.SqlInt16
的用法示例。
在下文中一共展示了SqlInt16.ToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToString
/// <summary>
/// Converts the value of the specified SqlInt16 to its equivalent String representation.
/// </summary>
/// <param name="value">An SqlInt16.</param>
/// <returns>The String equivalent of SqlInt16.</returns>
public static String ToString(SqlInt16 value) { return value.ToString(); }
示例2: ToString
/// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>String</c> value.</summary>
public static String ToString(SqlInt16 p) { return p.ToString(); }
示例3: Conversions
public void Conversions()
{
SqlInt16 Test12 = new SqlInt16(12);
SqlInt16 Test0 = new SqlInt16(0);
SqlInt16 TestNull = SqlInt16.Null;
SqlInt16 Test1000 = new SqlInt16(1000);
SqlInt16 Test288 = new SqlInt16(288);
// ToSqlBoolean ()
Assert.True(Test12.ToSqlBoolean().Value);
Assert.True(!Test0.ToSqlBoolean().Value);
Assert.True(TestNull.ToSqlBoolean().IsNull);
// ToSqlByte ()
Assert.Equal((byte)12, Test12.ToSqlByte().Value);
Assert.Equal((byte)0, Test0.ToSqlByte().Value);
try
{
SqlByte b = (byte)Test1000.ToSqlByte();
Assert.False(true);
}
catch (OverflowException e)
{
Assert.Equal(typeof(OverflowException), e.GetType());
}
// ToSqlDecimal ()
Assert.Equal(12, Test12.ToSqlDecimal().Value);
Assert.Equal(0, Test0.ToSqlDecimal().Value);
Assert.Equal(288, Test288.ToSqlDecimal().Value);
// ToSqlDouble ()
Assert.Equal(12, Test12.ToSqlDouble().Value);
Assert.Equal(0, Test0.ToSqlDouble().Value);
Assert.Equal(1000, Test1000.ToSqlDouble().Value);
// ToSqlInt32 ()
Assert.Equal(12, Test12.ToSqlInt32().Value);
Assert.Equal(0, Test0.ToSqlInt32().Value);
Assert.Equal(288, Test288.ToSqlInt32().Value);
// ToSqlInt64 ()
Assert.Equal(12, Test12.ToSqlInt64().Value);
Assert.Equal(0, Test0.ToSqlInt64().Value);
Assert.Equal(288, Test288.ToSqlInt64().Value);
// ToSqlMoney ()
Assert.Equal(12.0000M, Test12.ToSqlMoney().Value);
Assert.Equal(0, Test0.ToSqlMoney().Value);
Assert.Equal(288.0000M, Test288.ToSqlMoney().Value);
// ToSqlSingle ()
Assert.Equal(12, Test12.ToSqlSingle().Value);
Assert.Equal(0, Test0.ToSqlSingle().Value);
Assert.Equal(288, Test288.ToSqlSingle().Value);
// ToSqlString ()
Assert.Equal("12", Test12.ToSqlString().Value);
Assert.Equal("0", Test0.ToSqlString().Value);
Assert.Equal("288", Test288.ToSqlString().Value);
// ToString ()
Assert.Equal("12", Test12.ToString());
Assert.Equal("0", Test0.ToString());
Assert.Equal("288", Test288.ToString());
}
示例4: Conversions
public void Conversions()
{
SqlInt16 Test12 = new SqlInt16 (12);
SqlInt16 Test0 = new SqlInt16 (0);
SqlInt16 TestNull = SqlInt16.Null;
SqlInt16 Test1000 = new SqlInt16 (1000);
SqlInt16 Test288 = new SqlInt16(288);
// ToSqlBoolean ()
Assert ("TestA#1", Test12.ToSqlBoolean ().Value);
Assert ("TestA#2", !Test0.ToSqlBoolean ().Value);
Assert ("TestA#3", TestNull.ToSqlBoolean ().IsNull);
// ToSqlByte ()
AssertEquals ("TestB#1", (byte)12, Test12.ToSqlByte ().Value);
AssertEquals ("TestB#2", (byte)0, Test0.ToSqlByte ().Value);
try {
SqlByte b = (byte)Test1000.ToSqlByte ();
Fail ("TestB#4");
} catch (Exception e) {
AssertEquals ("TestB#5", typeof (OverflowException), e.GetType ());
}
// ToSqlDecimal ()
AssertEquals ("TestC#1", (decimal)12, Test12.ToSqlDecimal ().Value);
AssertEquals ("TestC#2", (decimal)0, Test0.ToSqlDecimal ().Value);
AssertEquals ("TestC#3", (decimal)288, Test288.ToSqlDecimal ().Value);
// ToSqlDouble ()
AssertEquals ("TestD#1", (double)12, Test12.ToSqlDouble ().Value);
AssertEquals ("TestD#2", (double)0, Test0.ToSqlDouble ().Value);
AssertEquals ("TestD#3", (double)1000, Test1000.ToSqlDouble ().Value);
// ToSqlInt32 ()
AssertEquals ("TestE#1", (int)12, Test12.ToSqlInt32 ().Value);
AssertEquals ("TestE#2", (int)0, Test0.ToSqlInt32 ().Value);
AssertEquals ("TestE#3", (int)288, Test288.ToSqlInt32().Value);
// ToSqlInt64 ()
AssertEquals ("TestF#1", (long)12, Test12.ToSqlInt64 ().Value);
AssertEquals ("TestF#2", (long)0, Test0.ToSqlInt64 ().Value);
AssertEquals ("TestF#3", (long)288, Test288.ToSqlInt64 ().Value);
// ToSqlMoney ()
AssertEquals ("TestG#1", 12.0000M, Test12.ToSqlMoney ().Value);
AssertEquals ("TestG#2", (decimal)0, Test0.ToSqlMoney ().Value);
AssertEquals ("TestG#3", 288.0000M, Test288.ToSqlMoney ().Value);
// ToSqlSingle ()
AssertEquals ("TestH#1", (float)12, Test12.ToSqlSingle ().Value);
AssertEquals ("TestH#2", (float)0, Test0.ToSqlSingle ().Value);
AssertEquals ("TestH#3", (float)288, Test288.ToSqlSingle().Value);
// ToSqlString ()
AssertEquals ("TestI#1", "12", Test12.ToSqlString ().Value);
AssertEquals ("TestI#2", "0", Test0.ToSqlString ().Value);
AssertEquals ("TestI#3", "288", Test288.ToSqlString ().Value);
// ToString ()
AssertEquals ("TestJ#1", "12", Test12.ToString ());
AssertEquals ("TestJ#2", "0", Test0.ToString ());
AssertEquals ("TestJ#3", "288", Test288.ToString ());
}
示例5: UpsertCatagory
public static void UpsertCatagory(SqlString name, SqlString parentNames, SqlInt16 haschild,SqlString url)
{
using (SqlConnection conn = new SqlConnection("context connection=true"))
{
conn.Open();
string[] parents = parentNames.ToString().Split('|');
string path = string.Empty;
foreach (string x in parents)
{
if (string.IsNullOrEmpty(x))
{
continue;
}
try
{
string id = FindCatIdByName(x, conn).ToString();
if (!string.IsNullOrEmpty(id))
{
path = (string.IsNullOrEmpty(path) ? id : path + "," + id);
}
else
{
throw new Exception(string.Format(" Parent cat: '{0}' is not found", x));
}
}
catch (Exception e)
{
throw new Exception("Error when find cataparents " + e.ToString());
}
}
if (FindCatIdByName(name.ToString(),conn) == string.Empty)//new row
{
string commandText = string.Format(@"select IDENT_CURRENT('bsp_categories')+1");
object nextId = null;
SqlCommand command = new SqlCommand(commandText, conn);
nextId = command.ExecuteScalar();
path = string.IsNullOrEmpty(parentNames.ToString()) == true ? nextId.ToString() : path + ',' + nextId.ToString();
string layer = string.IsNullOrEmpty(parentNames.ToString()) == true ? "1" : (parents.Length + 1).ToString();
string parentId = string.IsNullOrEmpty(parentNames.ToString()) == true ? "0" : path.Split(',')[path.Split(',').Length - 2];
commandText = string.Format(
@"SET IDENTITY_INSERT bsp_categories ON;"+
@"INSERT INTO bsp_categories(cateid,name,parentid,layer,haschild,path) " +
@"Values({5},'{0}',{1},{2},{3},'{4}');"+
@"SET IDENTITY_INSERT bsp_categories OFF;",
name.ToString(), parentId, layer, haschild.ToString(), path,nextId.ToString());
try
{
command.CommandText = commandText;
command.ExecuteNonQuery();
}
catch (Exception e)
{
throw new Exception(string.Format("Error when insert catatory : '{0}'", commandText), e);
}
commandText = string.Format(
@"SET IDENTITY_INSERT bsp_navs ON ;" +
@"INSERT INTO bsp_navs(id,pid,layer,name,url) " +
@"Values({0},{1},{2},'{3}','{4}');"+
@"SET IDENTITY_INSERT bsp_navs OFF;",
nextId, parentId, layer, name.ToString(), url.ToString());
try
{
SqlCommand insertNavsCommand = new SqlCommand(commandText, conn);
insertNavsCommand.ExecuteNonQuery();
}
catch (Exception e)
{
throw new Exception(string.Format("Error when insert nav : '{0}'", commandText), e);
}
}
conn.Close();
}
}