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


C# SQLiteConnection.Insert方法代码示例

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


在下文中一共展示了SQLiteConnection.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDatabaseConnection

		private SQLiteConnection GetDatabaseConnection() {
			var documents = Environment.GetFolderPath (Environment.SpecialFolder.Desktop);
			string db = Path.Combine (documents, "Occupation.db3");
			OccupationModel Occupation;

			// Create the database if it doesn't already exist
			bool exists = File.Exists (db);

			// Create connection to database
			var conn = new SQLiteConnection (db);

			// Initially populate table?
			if (!exists) {
				// Yes, build table
				conn.CreateTable<OccupationModel> ();

				// Add occupations
				Occupation = new OccupationModel ("Documentation Manager", "Manages the Documentation Group");
				conn.Insert (Occupation);

				Occupation = new OccupationModel ("Technical Writer", "Writes technical documentation and sample applications");
				conn.Insert (Occupation);

				Occupation = new OccupationModel ("Web & Infrastructure", "Creates and maintains the websites that drive documentation");
				conn.Insert (Occupation);

				Occupation = new OccupationModel ("API Documentation Manager", "Manages the API Doucmentation Group");
				conn.Insert (Occupation);

				Occupation = new OccupationModel ("API Documentor", "Creates and maintains API documentation");
				conn.Insert (Occupation);
			}

			return conn;
		}
开发者ID:RangoLee,项目名称:mac-samples,代码行数:35,代码来源:SubviewTableORMController.cs

示例2: DoSomeDataAccess

		/// <returns>
		/// Output of test query
		/// </returns>
		public static string DoSomeDataAccess ()
		{
			var output = "";
			output += "\nCreating database, if it doesn't already exist";
			string dbPath = Path.Combine (
				Environment.GetFolderPath (Environment.SpecialFolder.Personal), "ormdemo.db3");

			var db = new SQLiteConnection (dbPath);
			db.CreateTable<Stock> ();

			if (db.Table<Stock> ().Count() == 0) {
				// only insert the data if it doesn't already exist
				var newStock = new Stock ();
				newStock.Symbol = "AAPL";
				db.Insert (newStock); 

				newStock = new Stock ();
				newStock.Symbol = "GOOG";
				db.Insert (newStock); 

				newStock = new Stock ();
				newStock.Symbol = "MSFT";
				db.Insert (newStock);
			}

			output += "\nReading data using Orm";
			var table = db.Table<Stock> ();
			foreach (var s in table) {
				output += "\n" + s.Id + " " + s.Symbol;
			}

			return output;
		}
开发者ID:ARMoir,项目名称:mobile-samples,代码行数:36,代码来源:OrmExample.cs

示例3: KyPowerball

        private static void KyPowerball(SQLiteConnection connection)
        {
            string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            path = Path.Combine(path, "Powerball.txt");

            using (var stream = File.OpenRead(path))
            {
                using (var reader = new StreamReader(stream))
                {
                    while (!reader.EndOfStream)
                    {
                        string line = reader.ReadLine();
                        var split = line.Split('\t');

                        var win = new Win
                        {
                            Date = DateTime.Parse(split[0]),
                        };
                        connection.Insert(win);

                        var numbers = split[1].Split('–');
                        for (int i = 0; i < numbers.Length; i++)
                        {
                            connection.Insert(new Numbers
                            {
                                Number = int.Parse(numbers[i].Trim()),
                                Win = win.ID,
                                MegaBall = i == 5,
                            });
                        }
                    }
                }
            }
        }
开发者ID:jonathanpeppers,项目名称:KyLotto,代码行数:34,代码来源:Program.cs

示例4: TradeTable

        public TradeTable(SQLiteConnection database, TradeInstance trade)
        {
            var tradeClient0 = new TradeClient(database, trade.Client0Id, trade.Client0Monster);
            database.Insert(tradeClient0);
            TradeClient0Id = tradeClient0.Id;

            var tradeClient1 = new TradeClient(database, trade.Client1Id, trade.Client1Monster);
            database.Insert(tradeClient1);
            TradeClient1Id = tradeClient1.Id;
        }
开发者ID:PokeD,项目名称:PokeD.Server,代码行数:10,代码来源:TradeTable.cs

示例5: Save

        public static void Save(IEnumerable<Country> countryList, string connectionString)
        {
            if (countryList == null)
                throw new ArgumentNullException("countryList");

            using (SQLiteConnection connection = new SQLiteConnection(connectionString))
            {
                foreach (Country country in countryList)
                {
                    CountryDataObject countryDataObject = new CountryDataObject
                    {
                        name = country.Name,
                        is_important = country.IsHot ? 1 : 0
                    };

                    connection.Insert(countryDataObject);

                    foreach (Location location1 in country.Locations)
                    {
                        LocationDataObject location1DataObject = GetLocationDataObject(
                            location: location1,
                            parent_id: null,
                            country_id: countryDataObject.id);

                        connection.Insert(location1DataObject);

                        foreach (Location location2 in location1.Locations)
                        {
                            LocationDataObject location2DataObject = GetLocationDataObject(
                                location: location2,
                                parent_id: location1DataObject.id,
                                country_id: countryDataObject.id);

                            connection.Insert(location2DataObject);

                            foreach (Location location3 in location2.Locations)
                            {
                                LocationDataObject location3DataObject = GetLocationDataObject(
                                    location: location3,
                                    parent_id: location2DataObject.id,
                                    country_id: countryDataObject.id);

                                connection.Insert(location3DataObject);
                            }
                        }
                    }
                }
            }
        }
开发者ID:romanalexeev,项目名称:_travels,代码行数:49,代码来源:SqliteCountriesSaver.cs

示例6: CreateAccount

        public string CreateAccount(double _sum, String _name)
        {
            string res = "1;1";
            var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, dbname);
            using (var db = new SQLiteConnection(dbPath))
            {
                // Работа с БД
                var _acc = new AccountTable() { _Name = _name, CurrentMoneyAmount = _sum };
                db.Insert(_acc);
                var _change = new ChangesTable() { _DBString = "INSERT INTO AccountTable(_Name, CurrentMoneyAmount) VALUES('" + _name + "', '" + _sum + "');", _ChangesDatetime = DateTime.Now };
                db.Insert(_change);
            }

            return res;
        }
开发者ID:fireelf,项目名称:Winuibuh,代码行数:15,代码来源:Worker.cs

示例7: Insert

 public void Insert(Chinese chinese)
 {
     using (var db = new SQLiteConnection(dbPath))
     {
         db.RunInTransaction(() => db.Insert(chinese));
     }
 }
开发者ID:j-hayes,项目名称:Sample_cpp_WP8sqlite,代码行数:7,代码来源:ChineseManager.cs

示例8: RunCreateTest

        async Task RunCreateTest()
        {
            await Task.Factory.StartNew(() =>
            {
                using (var db = new SQLiteConnection(DatabasePath))
                {
                    db.CreateTable<Person>();
                    db.RunInTransaction(() =>
                    {
                        for (var i = 0; i < 10; i++)
                            db.Insert(new Person { FullName = "Person " + i });
                    });

                    var count = 0;
                    db.RunInTransaction(() =>
                    {
                        var table = db.Table<Person>();
                        count = table.Count();
                    });

                    var message = count == 10
                                ? "Completed!"
                                : string.Format("Only inserted {0} rows!", count);

                    dispatcher.RunIdleAsync(o => { CreateResult = message; });
                }

                
            });
        }
开发者ID:kiwipom,项目名称:billboard,代码行数:30,代码来源:SyncDatabaseViewModel.cs

示例9: InsertLocation

 public static void InsertLocation(Location Location)
 {
     using (var db = new SQLiteConnection(DatabasePath))
     {
         db.Insert(Location);
     }
 }
开发者ID:peterdn,项目名称:Geomoir,代码行数:7,代码来源:Database.cs

示例10: InsertLog

 public void InsertLog(Log log)
 {
     using (var connection = new SQLiteConnection(_dbPath) { Trace = true })
     {
         connection.Insert(log);
     }
 }
开发者ID:dylanbaxter,项目名称:SBDIL,代码行数:7,代码来源:DataConnection.cs

示例11: InsertOffender

 public void InsertOffender(Offender offender)
 {
     using (var connection = new SQLiteConnection(_dbPath) { Trace = true })
     {
         connection.Insert(offender);
     }
 }
开发者ID:dylanbaxter,项目名称:SBDIL,代码行数:7,代码来源:DataConnection.cs

示例12: btnAdd_TouchUpInside

partial         void btnAdd_TouchUpInside(UIButton sender)
        {
            // Input Validation: only insert a book if the title is not empty
            if (!string.IsNullOrEmpty(txtTitle.Text))
            {
                // Insert a new book into the database
                var newBook = new Book { BookTitle = txtTitle.Text, ISBN = txtISBN.Text };

                var db = new SQLiteConnection (filePath);
                db.Insert (newBook);

                // TODO: Add code to populate the Table View with the new values

                // show an alert to confirm that the book has been added
                new UIAlertView(
                    "Success",
                    string.Format("Book ID: {0} with Title: {1} has been successfully added!", newBook.BookId, newBook.BookTitle),
                    null,
                    "OK").Show();

                PopulateTableView();

                // call this method to refresh the Table View data
                tblBooks.ReloadData ();
            }
            else
            {
                new UIAlertView("Failed", "Enter a valid Book Title",null,"OK").Show();
            }
        }
开发者ID:idehao,项目名称:BookList-App,代码行数:30,代码来源:ViewController.cs

示例13: AddStocksToDb

		private static void AddStocksToDb(SQLiteConnection db, string symbol, string name, string file)
		{
			// parse the stock csv file
			const int NUMBER_OF_FIELDS = 7;    // The text file will have 7 fields, The first is the date, the last is the adjusted closing price
			TextParser parser = new TextParser(",", NUMBER_OF_FIELDS);     // instantiate our general purpose text file parser object.
			List<string[]> stringArrays;    // The parser generates a List of string arrays. Each array represents one line of the text file.
			stringArrays = parser.ParseText(File.Open(@"../../../DataAccess-Console/DAL/" + file,FileMode.Open));     // Open the file as a stream and parse all the text

			// Don't use the first array, it's a header
			stringArrays.RemoveAt(0);
			// Copy the List of strings into our Database
			int pk = 0;
			foreach (string[] stockInfo in stringArrays) {
				pk += db.Insert (new Stock () {
					Symbol = symbol,
					Name = name,
					Date = Convert.ToDateTime (stockInfo [0]),
					ClosingPrice = decimal.Parse (stockInfo [6])
				});
				// Give an update every 100 rows
				if (pk % 100 == 0)
					Console.WriteLine ("{0} {1} rows inserted", pk, symbol);
			}
			// Show the final count of rows inserted
			Console.WriteLine ("{0} {1} rows inserted", pk, symbol);			
		}
开发者ID:tvangeest,项目名称:CS235AM-Demos,代码行数:26,代码来源:Program.cs

示例14: Add

 public void Add(Account acc)
 {
     using (var connection = new SQLiteConnection(_dbPath))
     {
         connection.Insert(acc);
     }
 }
开发者ID:FLKone,项目名称:HFR4WinRT,代码行数:7,代码来源:AccountDataRepository.cs

示例15: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.gmail);

            // Create your application here
            EditText ed1 = FindViewById<EditText> (Resource.Id.editText1);
            EditText ed2 = FindViewById<EditText> (Resource.Id.editText2);
            Button save = FindViewById<Button> (Resource.Id.save);
            save.Click += delegate {
                string path = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
                SQLiteConnection dbConn = new SQLiteConnection (System.IO.Path.Combine (path, DbName));

                dbConn.CreateTable<Mail> ();
                // only insert the data if it doesn't already exist
                Mail newRw = new Mail ();
                newRw.mailId = ed1.Text;
                newRw.password = ed2.Text;
                dbConn.Insert (newRw);
                Toast toast = Toast.MakeText(this, "Sucessful", ToastLength.Long);
                toast.Show();
                StartActivity(typeof(MainActivity));
                Finish();

            };
        }
开发者ID:prabjotsingh50,项目名称:hackathon_1,代码行数:26,代码来源:gmail.cs


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