本文整理汇总了C#中SqlCeCommand.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCeCommand.GetValue方法的具体用法?C# SqlCeCommand.GetValue怎么用?C# SqlCeCommand.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlCeCommand
的用法示例。
在下文中一共展示了SqlCeCommand.GetValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main(string[] args)
{
string fileName;
if (args.Length > 0) fileName = args[0];
else
{
Console.WriteLine("You need to specify the path to the sdf file as a command-line argument!!");
return;
}
using (var connection = new SqlCeConnection(string.Format("Data Source={0}", fileName)))
{
connection.Open();
while (true)
{
Console.WriteLine("What?");
string commandText = Console.ReadLine().Trim();
if (commandText.Equals("exit") || commandText.Equals("quit")) return;
try
{
if (!commandText.ToLower().StartsWith("select"))
{
int count = new SqlCeCommand(commandText, connection).ExecuteNonQuery();
Console.WriteLine("Number of rows affected:\t{0}", count);
continue;
}
SqlCeDataReader reader = new SqlCeCommand(commandText, connection).ExecuteReader();
int columnCount;
for (int i = 0;; i++)
{
try
{
Console.Write("{0}\t", reader.GetName(i));
}
catch
{
columnCount = i;
break;
}
}
Console.WriteLine();
while (reader.Read())
{
for (int i = 0; i < columnCount; i++)
{
Console.Write("{0}\t", reader.GetValue(i));
}
Console.WriteLine();
}
}
catch (Exception e)
{
Console.WriteLine("There was an error!!! What did you do?");
Console.WriteLine("The error details are:");
Console.WriteLine(e);
Console.WriteLine("Let's try to not repeat it shall we!!");
}
}
}
}