当前位置: 首页>>代码示例>>C#>>正文


C# SqlCeCommand.Read方法代码示例

本文整理汇总了C#中SqlCeCommand.Read方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCeCommand.Read方法的具体用法?C# SqlCeCommand.Read怎么用?C# SqlCeCommand.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SqlCeCommand的用法示例。


在下文中一共展示了SqlCeCommand.Read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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!!");
             }
         }
     }
 }
开发者ID:srushti,项目名称:SqlCeReader,代码行数:59,代码来源:Program.cs

示例2: lbResults_DoubleClick

        private void lbResults_DoubleClick(object sender, EventArgs e)
        {
            // Show the bible verse
            if (lbResults.SelectedIndex >= 0)
            {
                string value = lbResults.SelectedItem.ToString();
                int keyIndex = value.IndexOf("Key: ") + 4;
                string key = value.Substring(keyIndex, value.IndexOf('\t', keyIndex) - keyIndex).Trim(';').Trim();
                int verseId = int.Parse(key);

                // Get the verse
                string sql = "SELECT v.*, b.* FROM Verse v INNER JOIN Book b ON v.BookID = b.BookID WHERE VerseID = " + verseId;
                string verse = string.Empty;
                using (SqlCeConnection conn = new SqlCeConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
                {
                    conn.Open();
                    SqlCeDataReader rdr = new SqlCeCommand(sql, conn).ExecuteReader();
                    rdr.Read();
                    verse = string.Format("{0} {1}:{2} - {3}", rdr["BookName"], rdr["BookNum"], rdr["VerseNum"], rdr["VerseText"]);
                    rdr.Close();
                }
                MessageBox.Show(verse);
            }
        }
开发者ID:darrencauthon,项目名称:CSharpQuery,代码行数:24,代码来源:frmTest.cs


注:本文中的SqlCeCommand.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。