private void frmFiyatGuncelle_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'barDataSet.Yiyecekler_Tablosu' table. You can move, or remove it, as needed. this.yiyecekler_TablosuTableAdapter.Fill(this.barDataSet.Yiyecekler_Tablosu); // TODO: This line of code loads data into the 'barDataSet.Icecekler_Tablosu' table. You can move, or remove it, as needed. // this.icecekler_TablosuTableAdapter.Fill(this.barDataSet.Icecekler_Tablosu); ; con = new SqlCeConnection(@"Data Source=|DataDirectory|\Bar.sdf"); con.Open(); da = new SqlCeDataAdapter("Select * from Icecekler_Tablosu", con); cmdb = new SqlCeCommandBuilder(da); ds = new DataSet(); da.Fill(ds, "Icecekler_Tablosu"); dataGridView1.DataSource = ds.Tables[0]; con.Close(); con2 = new SqlCeConnection(@"Data Source=|DataDirectory|\Bar.sdf"); con2.Open(); da2 = new SqlCeDataAdapter("Select * from Yiyecekler_Tablosu", con2); cmdb2 = new SqlCeCommandBuilder(da2); ds2 = new DataSet(); da2.Fill(ds2, "Yiyecekler_Tablosu"); dataGridView2.DataSource = ds2.Tables[0]; con2.Close(); }
public static DataTable Databaseadapter(SqlCeDataAdapter sda, string tablename) { using (SqlCeConnection cn = new SqlCeConnection(_connstring)) { //MessageBox.Show(tablename); sda = new SqlCeDataAdapter(string.Format("SELECT * FROM {0}", tablename), cn); sda.MissingSchemaAction = MissingSchemaAction.AddWithKey; SqlCeCommandBuilder sbuilder = new SqlCeCommandBuilder(sda); DataTable dt = new DataTable(); try { sda.Fill(dt); } catch (SqlCeException sqlex) { MessageBox.Show(sqlex.Message, "fail with filling dataset"); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { } return(dt); } }
private void ProfileForm_Load(object sender, EventArgs e) { if (LIForm != null || PForm != null) { if (LIForm == null) { PForm.Close(); } else if (PForm == null) { LIForm.Close(); } } // стави ја сликата на профилот. con.Open(); cmd.CommandText = "SELECT picture FROM PlayerTable WHERE username = '******'"; SqlCeDataAdapter da = new SqlCeDataAdapter(cmd); SqlCeCommandBuilder cmb = new SqlCeCommandBuilder(da); DataSet ds = new DataSet(); da.Fill(ds); con.Close(); byte[] ap = (byte[])(ds.Tables[0].Rows[0]["picture"]); MemoryStream ms = new MemoryStream(ap); pictureBox.Image = Image.FromStream(ms); pictureBox.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox.BorderStyle = BorderStyle.Fixed3D; ms.Close(); }
//This is kinda dirty. Be interesting to time delete / recreate all versus, seek - update or insert. //TODO: Wrapp a stopwatch around this public void SaveLibrary(NavigatableCollection <Track> library) { //Delete the library first DeleteLibrary(); //TODO: Repopulate it DataTable dt = new DataTable(); using (var objConn = new SqlCeConnection(ConnectionString)) { objConn.Open(); var adapter = new SqlCeDataAdapter("Select Id, TrackName, TrackPathName, Artist, TrackNumber, Album From Track", objConn); var objCommandBuilder = new SqlCeCommandBuilder(adapter); adapter.Fill(dt); foreach (var track in library) { dt.Rows.Add(new object[] { track.Id, track.TrackName, track.TrackPathName, track.Artist, null, track.Album }); //We're not currently parsing the track number } adapter.Update(dt); objConn.Close(); } }
private void button2_Click(object sender, EventArgs e) { try{ dataGridView1.DataSource = null; dataGridView1.Rows.Clear(); dataGridView1.Refresh(); String searchText = textBox1.Text; String query = "SELECT * FROM owner_master WHERE OwnerName LIKE '%" + searchText + "%'"; SqlCeDataAdapter adapter = new SqlCeDataAdapter(query, conn); SqlCeCommandBuilder commnder = new SqlCeCommandBuilder(adapter); DataTable dt = new DataTable(); adapter.Fill(dt); for (int i = 0; i < dataGridView1.Rows.Count; i++) { dataGridView1.Rows.Add(dt.Rows[i][0], dt.Rows[i][1], dt.Rows[i][2], dt.Rows[i][3]); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void conectaBD() { //busca la path de la aplicacion y le agrega la base de datos en string string path = "C:\\EM Software - Control_De_Invitados\\EM Software - Control_De_Invitados\\BD\\Control_de_invitados_BD.sdf;Persist Security Info=False;"; // C:\EM Software - Control_De_Invitados\EM Software - Control_De_Invitados\BD SqlCeConnection PathBD = new SqlCeConnection("Data source="+path); //abre la conexion try { string SeleccionaTodosLosDatos = "SELECT * FROM Invitados ORDER BY Num_invitado"; da = new SqlCeDataAdapter(SeleccionaTodosLosDatos, PathBD); // Crear los coma;ndos de insertar, actualizar y eliminar SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da); // Asignar los comandos al DataAdapter // (se supone que lo hace automáticamente, pero...) da.UpdateCommand = cb.GetUpdateCommand(); da.InsertCommand = cb.GetInsertCommand(); da.DeleteCommand = cb.GetDeleteCommand(); dt = new DataTable(); // Llenar la tabla con los datos indicados da.Fill(dt); PathBD.Open(); } catch (Exception w) { MessageBox.Show(w.ToString()); } }
private void GetData(string selectCommand) { try { // Specify a connection string. Replace the given value with a // valid connection string for a Northwind SQL Server sample // database accessible to your system. String connectionString = "Data Source=|DataDirectory|\\MyDatabase4.sdf"; // Create a new data adapter based on the specified query. dataAdapter = new SqlCeDataAdapter(selectCommand, connectionString); // Create a command builder to generate SQL update, insert, and // delete commands based on selectCommand. These are used to // update the database. SqlCeCommandBuilder commandBuilder = new SqlCeCommandBuilder(dataAdapter); // Populate a new data table and bind it to the BindingSource. DataTable table = new DataTable(); table.Locale = System.Globalization.CultureInfo.InvariantCulture; dataAdapter.Fill(table); bindingSource1.DataSource = table; // Resize the DataGridView columns to fit the newly loaded content. dataGridView1.AutoResizeColumns( DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); } catch (SqlCeException) { MessageBox.Show("To run this example, replace the value of the " + "connectionString variable with a connection string that is " + "valid for your system."); } }
private void modifica_copii_Load(object sender, EventArgs e) { var connString = (@"Data Source=" + System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)) + @"\Grupe.sdf"); using (var conn = new SqlCeConnection(connString)) { try { conn.Open(); var query = "SELECT * FROM copii WHERE Nume='" + nume2 + "'"; MessageBox.Show(query); var command = new SqlCeCommand(query, conn); SqlCeDataAdapter da = new SqlCeDataAdapter(command); SqlCeCommandBuilder cbd = new SqlCeCommandBuilder(da); DataSet ds = new DataSet(); da.Fill(ds); var dataAdapter = new SqlCeDataAdapter(command); var dataTable = new DataTable(); dataAdapter.Fill(dataTable); label5.Text = dataTable.Rows[0][1].ToString(); textBox2.Text = dataTable.Rows[0][2].ToString(); textBox3.Text = dataTable.Rows[0][3].ToString(); textBox4.Text = dataTable.Rows[0][4].ToString(); textBox5.Text = dataTable.Rows[0][5].ToString(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
/// <summary> /// Helper method for loading data from the database file into the DataGridView control. /// </summary> private void GetData() { DataTable table = null; try { dataGridViewDataAdapter = new SqlCeDataAdapter("SELECT * FROM Table1", @"Data Source=..\..\StudentGradesDB.sdf"); // Create a command builder to generate SQL update, insert, and delete commands based on select // command. These are used to update the database. commandBuilder = new SqlCeCommandBuilder(dataGridViewDataAdapter); commandBuilder.GetUpdateCommand(); // Populate a new data table and bind it to the BindingSource. table = new DataTable(); dataGridViewDataAdapter.Fill(table); dataGridViewBindingSource.DataSource = table; table = null; // Resize the DataGridView columns to fit the newly loaded content. DataGridViewStudentGrades.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); } finally { if (table != null) { table.Dispose(); } } }
public void conectaBD() { SqlCeConnection PathBD = new SqlCeConnection("Data Source=C:\\Facturacion\\Facturacion\\BaseDeDatos.sdf;Persist Security Info=False;"); //abre la conexion try { da = new SqlCeDataAdapter("SELECT * FROM USUARIOS ORDER BY ID_USUARIO", PathBD); // Crear los comandos de insertar, actualizar y eliminar SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da); // Asignar los comandos al DataAdapter // (se supone que lo hace automáticamente, pero...) da.UpdateCommand = cb.GetUpdateCommand(); da.InsertCommand = cb.GetInsertCommand(); da.DeleteCommand = cb.GetDeleteCommand(); dt = new DataTable(); // Llenar la tabla con los datos indicados da.Fill(dt); PathBD.Open(); } catch (Exception w) { MessageBox.Show(w.ToString()); return; } }
public DbCommandBuilder GetCommandBuilder(DbDataAdapter adapter) { try { switch (adapter) { case SQLiteDataAdapter _: CommandBuilder = new SQLiteCommandBuilder(adapter as SQLiteDataAdapter); return(CommandBuilder); case OleDbDataAdapter _: CommandBuilder = new OleDbCommandBuilder(adapter as OleDbDataAdapter); return(CommandBuilder); case SqlCeDataAdapter _: CommandBuilder = new SqlCeCommandBuilder(adapter as SqlCeDataAdapter); return(CommandBuilder); case SqlDataAdapter _: CommandBuilder = new SqlCommandBuilder(adapter as SqlDataAdapter); return(CommandBuilder); default: return(null); } } catch (SystemException ex) { new Error(ex).ShowDialog(); return(null); } }
public override DbDataAdapter CreateAdapter(Table table, TableFilter filter) { var sqlTable = table as SqlCeTable; if (sqlTable == null) { throw new InvalidOperationException("Table should be an SqlCeTable"); } var adapter = new SqlCeDataAdapter(table.GetBaseSelectCommandText(filter), this.connection); if (!table.IsReadOnly) { var builder = new SqlCeCommandBuilder(adapter); builder.ConflictOption = ConflictOption.OverwriteChanges; try { adapter.UpdateCommand = builder.GetUpdateCommand(); adapter.InsertCommand = builder.GetInsertCommand(); adapter.DeleteCommand = builder.GetDeleteCommand(); } catch (InvalidOperationException) { sqlTable.SetReadOnly(true); return(adapter); } } return(adapter); }
public override void Load()//DataSet ds=null) // Параметром передовать датасет { if (Adapter == null) { string sql = "SELECT * FROM " + TableName + ";";//+ " ORDER BY Id;"; Adapter = new SqlCeDataAdapter(sql, DBase.Connection); // Для commandBuilder необходим хотябы один первичный ключ // столбец первичного ключа или столбец с атрибутом UNIQUE commandBuilder = new SqlCeCommandBuilder(); commandBuilder.DataAdapter = Adapter; Adapter.UpdateBatchSize = 1; Adapter.RowUpdating += new SqlCeRowUpdatingEventHandler(RowUpdating); Adapter.RowUpdated += new SqlCeRowUpdatedEventHandler(RowUpdated); } else { //dataSet.Clear(); } Adapter.Fill(classBase.dataSet); dataTable = classBase.dataSet.Tables["Table"]; dataTable.TableName = TableName; if (SetDataViewOnLoad) { SetDataView(null); } //dataView = new DataView(dataTable);//dataSet.Tables[0]); //SortIndex = sortIndex; }
private void button6_Click(object sender, EventArgs e) { try { if (dataGridView1.SelectedRows.Count > 0) { float t0 = float.Parse(textBox2.Text); t0 = float.Parse(textBox3.Text); t0 = float.Parse(textBox4.Text); t0 = float.Parse(textBox5.Text); t0 = float.Parse(textBox6.Text); t0 = float.Parse(textBox7.Text); t0 = float.Parse(textBox8.Text); dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[0].Value = textBox0.Text.Trim(); dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[1].Value = textBox1.Text.Trim(); dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[2].Value = textBox2.Text.Trim(); dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[3].Value = textBox3.Text.Trim(); dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[4].Value = textBox4.Text.Trim(); dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[5].Value = textBox5.Text.Trim(); dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[6].Value = textBox6.Text.Trim(); dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[7].Value = textBox7.Text.Trim(); dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[8].Value = textBox8.Text.Trim(); MessageBox.Show("la modification demandée a été effectuée", "", MessageBoxButtons.OK, MessageBoxIcon.Information); vidange(); Services.remplie = true; Services.daTarif = new SqlCeDataAdapter("select * from " + Table, Services.con); Services.daTarif.Fill(Services.ds, Table); for (int i = 0; i < dataGridView1.Rows.Count; i++) { DataRow row = Services.ds.Tables[Table].NewRow(); row[0] = i; for (int j = 0; j < dataGridView1.Rows[i].Cells.Count; j++) { row[j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString(); } Services.ds.Tables[Table].Rows.Add(row); } SqlCeCommandBuilder cmd = new SqlCeCommandBuilder(Services.daTarif); Services.daTarif.Update(Services.ds, Table); actualiser(); viderChamp(); } else { MessageBox.Show("Aucune ligne n'est sélectionné", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private bool MigrateData(string sdfFilePath, string sqlExpressConnectionString) { bool isSuccessful = true; try { string sdfConnectionString = string.Format("Data Source={0}", sdfFilePath); SqlCeConnection ceCon = new SqlCeConnection(sdfConnectionString); SqlConnection con = new SqlConnection(sqlExpressConnectionString); SqlCeDataAdapter ceAdp = new SqlCeDataAdapter("SELECT * FROM INFORMATION_SCHEMA.TABLES", ceCon); DataSet dataset = new DataSet("dataset"); dataset.Tables.Add("Names"); ceAdp.Fill(dataset.Tables["Names"]); DataSet sdfDataset = new DataSet("sdfDataset"); for (int i = 0; i < dataset.Tables["Names"].Rows.Count; i++) { string tableName = (string)dataset.Tables["Names"].Rows[i]["table_name"]; sdfDataset.Tables.Add(tableName); ceAdp = new SqlCeDataAdapter("select * from [" + tableName + "]", ceCon); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(ceAdp); try { ceAdp.Fill(sdfDataset.Tables[tableName]); } catch (Exception e) { Console.WriteLine("exception= " + e.Message); } } foreach (DataTable tableName in sdfDataset.Tables) { con.Open(); using (SqlBulkCopy bulkcopy = new SqlBulkCopy(con)) { bulkcopy.DestinationTableName = "dbo.[" + tableName + "]"; try { bulkcopy.WriteToServer(tableName); } catch (Exception ex) { Console.WriteLine(ex.Message); } con.Close(); } } } catch (Exception ex) { isSuccessful = false; } return(isSuccessful); }
private void UpdateDataBase() { conn.Open(); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da); da.Update(ds.Tables[0]); conn.Close(); dirtyData = false; }
private bool MigrateData(string sdfFilePath, string sqlExpressConnectionString) { bool isSuccessful = true; try { string sdfConnectionString = string.Format("Data Source={0}",sdfFilePath); SqlCeConnection ceCon = new SqlCeConnection(sdfConnectionString); SqlConnection con = new SqlConnection(sqlExpressConnectionString); SqlCeDataAdapter ceAdp = new SqlCeDataAdapter("SELECT * FROM INFORMATION_SCHEMA.TABLES", ceCon); DataSet dataset = new DataSet("dataset"); dataset.Tables.Add("Names"); ceAdp.Fill(dataset.Tables["Names"]); DataSet sdfDataset = new DataSet("sdfDataset"); for (int i = 0; i < dataset.Tables["Names"].Rows.Count; i++) { string tableName = (string)dataset.Tables["Names"].Rows[i]["table_name"]; sdfDataset.Tables.Add(tableName); ceAdp = new SqlCeDataAdapter("select * from [" + tableName + "]", ceCon); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(ceAdp); try { ceAdp.Fill(sdfDataset.Tables[tableName]); } catch (Exception e) { Console.WriteLine("exception= " + e.Message); } } foreach (DataTable tableName in sdfDataset.Tables) { con.Open(); using (SqlBulkCopy bulkcopy = new SqlBulkCopy(con)) { bulkcopy.DestinationTableName = "dbo.[" + tableName + "]"; try { bulkcopy.WriteToServer(tableName); } catch (Exception ex) { Console.WriteLine(ex.Message); } con.Close(); } } } catch (Exception ex) { isSuccessful = false; } return isSuccessful; }
private void updateDatabase() { SqlCeCommand cmd = new SqlCeCommand(CmdString, con); SqlCeDataAdapter sda = new SqlCeDataAdapter(cmd); SqlCeCommandBuilder com = new SqlCeCommandBuilder(sda); DataSet ds = new DataSet(); sda.Update(dt); dt.Clear(); sda.Fill(dt); }
public void GridData() { var sqlDataAdapter = new SqlCeDataAdapter("Select * from User_rec", @"Data Source=C:\Users\Koushik\Documents\Visual Studio 2010\Projects\Minor Project\Citizen_Interaction\Citizen_Interaction\cidb13.sdf"); var sqlCommandBuilder = new SqlCeCommandBuilder(sqlDataAdapter); var dataTable = new DataTable(); sqlDataAdapter.Fill(dataTable); var bindingSource = new BindingSource(); bindingSource.DataSource = dataTable; dataGridView1.DataSource = bindingSource; }
public static DataSet GetAvailableReplacementsAsDatasetForTextConversion(int captureEventId, SqlCeConnection conn) { SqlCeCommand getAllReplacementsByCaptureIDCommand = new SqlCeCommand(Advanced_Replacements_TextConv_SQL.commandGetCapturePointReplacementsTextConv, conn); getAllReplacementsByCaptureIDCommand.Parameters.Add("@capturePointId", captureEventId); DataSet dataSet = new DataSet(); SqlCeDataAdapter da = new SqlCeDataAdapter(getAllReplacementsByCaptureIDCommand); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da); da.Fill(dataSet); return dataSet; }
public ScoreDT() { _Connection = new SqlCeConnection(); _Connection.ConnectionString = Global.ConnectionString; _DataAdapter = new SqlCeDataAdapter("SELECT TOP (20) * FROM tHighScore", _Connection); _Builder = new SqlCeCommandBuilder(_DataAdapter); _DataAdapter.Fill(this); }
public DataTable executeForUpdate(string sql) { dataAdapter = new SqlCeDataAdapter(sql, connect); SqlCeCommandBuilder cmdBuilder = new SqlCeCommandBuilder(dataAdapter); string ts = cmdBuilder.GetInsertCommand().CommandText; DataSet dSet = new DataSet("dt"); dataAdapter.Fill(dSet, "dt"); return(dSet.Tables[0]); }
public void guncelleme() { con = new SqlCeConnection(@"Data Source=|DataDirectory|\Bar.sdf"); con.Open(); da = new SqlCeDataAdapter("Select * from Oda1Adisyon", con); cmdb = new SqlCeCommandBuilder(da); ds = new DataSet(); da.Fill(ds, "Oda1Adisyon"); dataGridView1.DataSource = ds.Tables[0]; con.Close(); }
private void Form2_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'angajatiDataSet1.info' table. You can move, or remove it, as needed. this.infoTableAdapter.Fill(this.angajatiDataSet1.info); var connString = (@"Data Source=" + System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)) + @"\Angajati.sdf"); using (var conn = new SqlCeConnection(connString)) { try { conn.Open(); var query = "SELECT * FROM info WHERE Prenume='" + prenume + "' AND Nume='" + nume + "'"; var command = new SqlCeCommand(query, conn); SqlCeDataAdapter da = new SqlCeDataAdapter(command); SqlCeCommandBuilder cbd = new SqlCeCommandBuilder(da); DataSet ds = new DataSet(); da.Fill(ds); var dataAdapter = new SqlCeDataAdapter(command); var dataTable = new DataTable(); dataAdapter.Fill(dataTable); dataAdapter.Fill(dataTable); byte[] ap = (byte[])(ds.Tables[0].Rows[0]["Poza"]); MemoryStream ms = new MemoryStream(ap); pictureBox1.Image = Image.FromStream(ms); pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; label1.Text = dataTable.Rows[0][1].ToString(); label2.Text = dataTable.Rows[0][2].ToString(); label3.Text = dataTable.Rows[0][3].ToString(); label4.Text = dataTable.Rows[0][4].ToString(); label5.Text = dataTable.Rows[0][5].ToString(); label14.Text = (dataTable.Rows[0][7].ToString()); label21.Text = (dataTable.Rows[0][8].ToString()); textBox1.Text = (dataTable.Rows[0][9].ToString()); textBox2.Text = (dataTable.Rows[0][10].ToString()); textBox4.Text = (dataTable.Rows[0][11].ToString()); textBox5.Text = (dataTable.Rows[0][12].ToString()); textBox6.Text = (dataTable.Rows[0][13].ToString()); textBox7.Text = (dataTable.Rows[0][14].ToString()); textBox8.Text = (dataTable.Rows[0][15].ToString()); double baza = label21.Text == "" ? 0 : double.Parse(label21.Text); textBox10.Text = ((baza *75)/1000).ToString(); textBox11.Text = ((baza * 100) / 1000).ToString(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
/// <summary> /// Save the changed values in the table /// </summary> /// <param name="sender">contains the sender of the event, so if you had one method bound to multiple controls, you can distinguish them.</param> /// <param name="e">refers to the event arguments for the used event, they usually come in the form of properties/functions/methods that get to be available on it.</param> private void btnSave_Click(object sender, EventArgs e) { try { this.Validate(); if (dgvList.IsCurrentRowDirty || dgvList.IsCurrentCellDirty) { dgvList.CommitEdit(DataGridViewDataErrorContexts.Commit); dgvList.EndEdit(); } string tableName = Ribbon.AppVariables.TableName; string sql = "SELECT * FROM " + tableName; //string sql = "SELECT * FROM @tableName"; SqlCeConnection cn = new SqlCeConnection(Data.Connection()); SqlCeCommandBuilder scb = default(SqlCeCommandBuilder); SqlCeDataAdapter sda = new SqlCeDataAdapter(sql, cn); //TODO: use this parameterized query... //sda.SelectCommand.Parameters.AddWithValue("@tableName", tableName); //sda.SelectCommand.Parameters.AddWithValue("@tableName", System.Data.SqlDbType.NVarChar).Value = tableName; //sda.SelectCommand.Parameters.Add(new SqlCeParameter //{ // ParameterName = "@tableName" // , Value = tableName // , SqlDbType = System.Data.SqlDbType.NVarChar // , Size = 50 //}); sda.TableMappings.Add("Table", tableName); scb = new SqlCeCommandBuilder(sda); switch (tableName) { case "TableAlias": sda.Update(Data.TableAliasTable); Data.CreateTableAliasTable(); break; case "DateFormat": sda.Update(Data.DateFormatTable); Data.CreateDateFormatTable(); break; case "TimeFormat": sda.Update(Data.TimeFormatTable); Data.CreateDateFormatTable(); break; } Ribbon.ribbonref.InvalidateRibbon(); } catch (Exception ex) { ErrorHandler.DisplayMessage(ex); } }
//ADAPTER public SqlCeDataAdapter CeAdatpter(string sql) { if (connection.State.ToString() == "Closed") { connection.Open(); } dataSet = new DataSet(); adapter.SelectCommand = new SqlCeCommand(sql.Replace("zbroj", "+"), connection); SqlCeCommandBuilder builder = new SqlCeCommandBuilder(adapter); return(adapter); }
private void Save_Button_Click(object sender, RoutedEventArgs e) { using (var cmd = new SqlCeCommand("SELECT * FROM CompanyInfo", database_.GetConnection())) { SqlCeDataAdapter adapter = new SqlCeDataAdapter(cmd); SqlCeCommandBuilder builder = new SqlCeCommandBuilder(adapter); adapter.UpdateCommand = builder.GetUpdateCommand(); adapter.Update(company_); } company_.AcceptChanges(); DialogResult = true; }
public void SaveTableDataChanges(DataTable tableData) { if (tableData == null) { return; } using (var conn = new SqlCeConnection(ConnectionString)) using (var adapter = new SqlCeDataAdapter("SELECT * FROM " + tableData.TableName, conn)) using (var commands = new SqlCeCommandBuilder(adapter)) adapter.Update(tableData); }
private void button2_Click(object sender, EventArgs e) { try { if (dataGridView1.Rows.Count <= 0) { MessageBox.Show("La liste des accessoires est vide", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); viderChamp(); //groupBox5.Enabled = false; //groupBox4.Enabled = false; } else { choix(); vidange(); Services.remplie = true; Services.daTarif = new SqlCeDataAdapter("select * from " + Table, Services.con); Services.daTarif.Fill(Services.ds, Table); for (int i = 0; i < dataGridView1.Rows.Count; i++) { DataRow row = Services.ds.Tables[Table].NewRow(); row[0] = i; for (int j = 0; j < dataGridView1.Rows[i].Cells.Count; j++) { row[j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString(); } Services.ds.Tables[Table].Rows.Add(row); } SqlCeCommandBuilder cmd = new SqlCeCommandBuilder(Services.daTarif); Services.daTarif.Update(Services.ds, Table); if (sender != null) { MessageBox.Show("L'enregistrement a été effectué avec succès", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("L'importation a été effectué avec succès", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } actualiser(); viderChamp(); //groupBox5.Enabled = false; //groupBox4.Enabled = false; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// 保存设置到数据库 private void Save_Settings_Button_Click(object sender, RoutedEventArgs e) { using (var cmd = new SqlCeCommand("SELECT * FROM Settings", database_.GetConnection())) { SqlCeDataAdapter adapter = new SqlCeDataAdapter(cmd); SqlCeCommandBuilder builder = new SqlCeCommandBuilder(adapter); adapter.UpdateCommand = builder.GetUpdateCommand(); adapter.Update(settings_); } settings_.AcceptChanges(); textBoxMessage.Text = "设置已保存"; }
public static DataSet GetAppPrefsDataset() { SqlCeConnection conn = BackEndUtils.GetSqlConnection(); DataSet dataSet = new DataSet(); try { SqlCeDataAdapter da = new SqlCeDataAdapter(Application_Settings_SQL.commandGetAllAppConfig, conn); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da); da.Fill(dataSet); } finally { conn.Close(); } return dataSet; }
private void Adminka_Load(object sender, EventArgs e) { SqlCeConnection con = new SqlCeConnection(Properties.Settings.Default.DBConnection); string query = "SELECT * FROM AdminTest"; adap = new SqlCeDataAdapter(query, con); SqlCeCommandBuilder cBuilder = new SqlCeCommandBuilder(adap); adap.Fill(dataT); bindS.DataSource = dataT; dataGridView1.DataSource = bindS; }
public static DataSet GetAllAdvancedRecCategoriesAsDataset() { SqlCeConnection conn = BackEndUtils.GetSqlConnection(); DataSet dataSet = new DataSet(); try { SqlCeDataAdapter da = new SqlCeDataAdapter(Advanced_Recommendation_Categories_SQL.commandGetAllCaptureCategories, conn); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da); da.Fill(dataSet); } finally { conn.Close(); } return dataSet; }
private void RefreshDataGridView() { ds = new DataSet(); con.Open(); da = new SqlCeDataAdapter("Select * from tblBudgetSelger WHERE BudgetId =" + budgetId, con); var cmdBldr = new SqlCeCommandBuilder(da); da.Fill(ds, "tblBudgetSelger"); bindingSource1.DataSource = ds; bindingSource1.DataMember = "tblBudgetSelger"; dataGridView1.DataSource = bindingSource1; bindingNavigator1.BindingSource = bindingSource1; con.Close(); }
private void buttonSave_Click(object sender, EventArgs e) { con = new SqlCeConnection(source); con.Open(); cmd = new SqlCeCommand(@"Select * From Persons ", con); adapter = new SqlCeDataAdapter(cmd); SqlCeCommandBuilder CB = new SqlCeCommandBuilder(adapter); adapter.Update(dataSet); MessageBox.Show("Сохранено!"); }
public static DataSet GetAllFolderNamesAsDataset() { SqlCeConnection conn = BackEndUtils.GetSqlConnection(); DataSet dataSet = new DataSet(); try { SqlCeDataAdapter da = new SqlCeDataAdapter(Folder_Names_SQL.commandGetAllFolderNamesTable, conn); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da); da.Fill(dataSet); } finally { conn.Close(); } return dataSet; }
internal static void GetProductsData(DataSet dataSet, string tableName) { SqlCeCommandBuilder cmdBldr; if (dbCon.State == ConnectionState.Closed) { dbCon.Open(); } DBManager.dataAdapter = new SqlCeDataAdapter("Select * from " + tableName, dbCon); cmdBldr = new SqlCeCommandBuilder(dataAdapter); dataAdapter.Fill(dataSet, tableName); dbCon.Close(); }
private void Doctor_Load(object sender, EventArgs e) { // Open the connection just when needed, // Initialize the adapter here and call the CommandBuider constructor to force // the initialization of the internal adapter commands using (SqlCeConnection con = new SqlConnection(.....)) { DataTable t = new DataTable(); a = new SqlCeDataAdapter("SELECT * FROM Doctor", con); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(a); a.Fill(t); DoctorView.DataSource = t; } }
//UPDATE public static string update(string sql) { //sql = sql.Replace('\'', ' '); if (remoteConnectionString == "") { try { { if (connection.State.ToString() == "Closed") { connection.Open(); } dataSet = new DataSet(); adapter.SelectCommand = new SqlCeCommand(sql, connection); SqlCeCommandBuilder builder = new SqlCeCommandBuilder(adapter); adapter.Fill(dataSet); connection.Close(); } return(""); } catch (Exception ex) { connection.Close(); OstaleFunkcije.SetInLog(sql + "\r\n" + ex.ToString(), "65", "RemoteDB"); return(ex.ToString()); } } else { try { if (remoteConnection.State.ToString() == "Closed") { remoteConnection.Open(); } NpgsqlCommand comm = new NpgsqlCommand(sql, remoteConnection); comm.CommandTimeout = 1200; comm.ExecuteNonQuery(); remoteConnection.Close(); return(""); } catch (NpgsqlException ex) { remoteConnection.Close(); OstaleFunkcije.SetInLog(sql + "\r\n" + ex.ToString(), "65", "RemoteDB"); return(ex.ToString()); } } }
public static DataTable GetAllAppEnums() { SqlCeConnection conn = BackEndUtils.GetSqlConnection(); SqlCeCommand Command = new SqlCeCommand(ApplicationEnums_SQL.commandGetAllApplicationEnums, conn); DataSet dataSet = new DataSet(); try { SqlCeDataAdapter da = new SqlCeDataAdapter(Command); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da); da.Fill(dataSet); } finally { conn.Close(); } return dataSet.Tables[0]; }
public static DataSet GetAllAvailableEnvCompCategsAsDataset() { SqlCeConnection conn = BackEndUtils.GetSqlConnection(); SqlCeCommand Command = new SqlCeCommand(Env_Comparison_Categories_SQL.commandSelectAllEnvComparisonCategory, conn); DataSet dataSet = new DataSet(); try { SqlCeDataAdapter da = new SqlCeDataAdapter(Command); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da); da.Fill(dataSet); } finally { conn.Close(); } return dataSet; }
public LocalDatabase(string FilePath) : base() { try { string fileName = Path.Combine(FilePath, "caselist.sdf"); connectionString = string.Format("Data Source=\"{0}\"", fileName); SqlCeEngine en = new SqlCeEngine(connectionString); if (!File.Exists(fileName)) { en.CreateDatabase(); } m_connection = new SqlCeConnection(); m_connection.ConnectionString = connectionString; if (m_connection.State == System.Data.ConnectionState.Closed) { try { m_connection.Open(); } catch (SqlCeInvalidDatabaseFormatException) { en.Upgrade(); m_connection.Open(); } } SqlCeCommand SelectTableCommand = new SqlCeCommand(); SelectTableCommand.CommandText = QuerySelectRowString; SelectTableCommand.Connection = m_connection; m_adapter = new SqlCeDataAdapter((SqlCeCommand)SelectTableCommand); // Create the DbCommandBuilder. m_builder = new SqlCeCommandBuilder(); m_builder.DataAdapter = m_adapter; m_adapter.SelectCommand = SelectTableCommand; } catch { throw; } }
public LocalDatabase(string FilePath) : base() { try { string fileName = Path.Combine(FilePath, "caselist.sdf"); connectionString = string.Format("Data Source=\"{0}\"", fileName); SqlCeEngine en = new SqlCeEngine(connectionString); if (!File.Exists(fileName)) { en.CreateDatabase(); } m_connection = new SqlCeConnection(); m_connection.ConnectionString = connectionString; if (m_connection.State == System.Data.ConnectionState.Closed) { try { m_connection.Open(); } catch (SqlCeInvalidDatabaseFormatException) { en.Upgrade(); m_connection.Open(); } } SqlCeCommand SelectTableCommand = new SqlCeCommand(); SelectTableCommand.CommandText = QuerySelectRowString; SelectTableCommand.Connection = m_connection; m_adapter = new SqlCeDataAdapter((SqlCeCommand)SelectTableCommand); // Create the DbCommandBuilder. m_builder = new SqlCeCommandBuilder(); m_builder.DataAdapter = m_adapter; m_adapter.SelectCommand = SelectTableCommand; } catch { throw; } }
public static DataSet GetAllTableNamesAsDataSet() { //select table_name from information_schema.tables where TABLE_TYPE <> 'VIEW' SqlCeConnection conn = GetSqlConnection(); SqlCeCommand Command = new SqlCeCommand("select table_name from information_schema.tables where TABLE_TYPE <> 'VIEW'", conn); DataSet dataSet = new DataSet(); try { SqlCeDataAdapter da = new SqlCeDataAdapter(Command); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da); da.Fill(dataSet); } finally { conn.Close(); } return dataSet; }
private void Form1_Load(object sender, EventArgs e) { // gridPersons.DataSource = System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Faces"); try { sconn = new SqlCeConnection("Data Source=" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\FaceDataBase.sdf;Persist Security Info=false;Password=sasol321;"); scommand = new SqlCeCommand("select * from Persons", sconn); sda = new SqlCeDataAdapter(scommand); cb = new SqlCeCommandBuilder(sda); sda.InsertCommand = cb.GetInsertCommand(); sda.DeleteCommand = cb.GetDeleteCommand(); sda.UpdateCommand = cb.GetUpdateCommand(); personTable = new DataTable(); //gridPersons.AutoGenerateColumns = true; gridPersons.DataSource = personTable; sda.Fill(personTable); gridPersons.Columns[0].HeaderText = "شناسه"; gridPersons.Columns[1].HeaderText = "نام"; gridPersons.Columns[2].HeaderText = "سن"; gridPersons.Columns[3].HeaderText = "جنسیت"; gridPersons.Columns[4].HeaderText = "مسیر"; gridPersons.Columns[5].HeaderText = "تصویر"; ((DataGridViewImageColumn)gridPersons.Columns[5]).ImageLayout = DataGridViewImageCellLayout.Stretch; gridPersons.Columns[5].Width = 150; //gridPersons.Columns[4].Width = 100; for (int i = 0; i < gridPersons.Rows.Count; i++) { gridPersons.Rows[i].Height = 150; } } catch (Exception ex) { MessageBox.Show(ex.Message); } capturer = new FaceLib.Capturer(); faceExaminer = new FaceLib.FaceExaminer(); faceTrainer = new FaceLib.FaceTrainer(); }
private void Save_Click(object sender, EventArgs e) { using (SqlCeConnection con = new SqlCeConnection(.....)) { // Prepare again the adapter with a valid select command SqlCeDataAdapter a = new SqlCeDataAdapter("SELECT * FROM Doctor", con); // Force the building of the internal command objects of the adapter SqlCeCommandBuilder cb = new SqlCeCommandBuilder(a); // Recover the datatable from the datasource of the grid DataTable t = DoctorView.DataSource as DataTable; // Update the table with DataRows changed, deleted or inserted a.Update(t); } }
public CampaignRepositorySql() { string selCampaigns = "select * from CampaignStates"; string selPlayers = "select * from Player"; string cs = ConfigurationManager.ConnectionStrings["GcmlDbContext"].ConnectionString; conn = new SqlCeConnection(cs); daCampaignStates = new SqlCeDataAdapter(selCampaigns, conn); daPlayers = new SqlCeDataAdapter(selPlayers, conn); SqlCeCommandBuilder cpcampaigns = new SqlCeCommandBuilder(daCampaignStates); SqlCeCommandBuilder cpplayers = new SqlCeCommandBuilder(daPlayers); ds = new GcmlData(); daCampaignStates.Fill(ds.CampaignStates); daPlayers.Fill(ds.Player); }
//UPDATE public static string update(string sql) { if (remoteConnectionString == "") { try { { if (connection.State == ConnectionState.Closed) { connection.Open(); } dataSet = new DataSet(); adapter.SelectCommand = new SqlCeCommand(sql, connection); SqlCeCommandBuilder builder = new SqlCeCommandBuilder(adapter); adapter.Fill(dataSet); } return(""); } catch (Exception ex) { connection.Close(); return(ex.ToString()); } } else { try { if (remoteConnection.State == ConnectionState.Closed) { remoteConnection.Open(); } NpgsqlCommand comm = new NpgsqlCommand(sql, remoteConnection); comm.CommandTimeout = 180; comm.ExecuteNonQuery(); remoteConnection.Close(); return(""); } catch (NpgsqlException ex) { remoteConnection.Close(); return(ex.ToString()); } } }
public void UpdateGrid() { ds = new DataSet(); con.Open(); if (toolStripComboBoxFilterKat.Text != "Alle" && !String.IsNullOrEmpty(toolStripComboBoxFilterKat.Text)) da = new SqlCeDataAdapter("SELECT * FROM tblVinnprodukt WHERE Avdeling = " + main.appConfig.Avdeling + " AND Kategori = '" + toolStripComboBoxFilterKat.Text + "'", con); else da = new SqlCeDataAdapter("SELECT * FROM tblVinnprodukt WHERE Avdeling = " + main.appConfig.Avdeling, con); var cmdBldr = new SqlCeCommandBuilder(da); da.Fill(ds, "tblVinnprodukt"); bindingSource1.DataSource = ds; bindingSource1.DataMember = "tblVinnprodukt"; dataGridView1.DataSource = bindingSource1; bindingNavigator1.BindingSource = bindingSource1; con.Close(); }
private void Modifica_Load(object sender, EventArgs e) { var connString = (@"Data Source=" + System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)) + @"\Angajati.sdf"); using (var conn = new SqlCeConnection(connString)) { try { conn.Open(); var query = "SELECT * FROM info WHERE Prenume='" + prenume + "' AND Nume='" + nume + "'"; var command = new SqlCeCommand(query, conn); SqlCeDataAdapter da = new SqlCeDataAdapter(command); SqlCeCommandBuilder cbd = new SqlCeCommandBuilder(da); DataSet ds = new DataSet(); da.Fill(ds); var dataAdapter = new SqlCeDataAdapter(command); var dataTable = new DataTable(); dataAdapter.Fill(dataTable); dataAdapter.Fill(dataTable); byte[] ap = (byte[])(ds.Tables[0].Rows[0]["Poza"]); MemoryStream ms = new MemoryStream(ap); pictureBox1.Image = Image.FromStream(ms); pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; textBox5.Text = dataTable.Rows[0][1].ToString(); textBox4.Text = dataTable.Rows[0][2].ToString(); label1.Text = dataTable.Rows[0][3].ToString(); label2.Text = ("Proiect: " + dataTable.Rows[0][4]).ToString(); label3.Text = ("Schimburi: " + dataTable.Rows[0][5].ToString()); label7.Text = ("Acord: " + dataTable.Rows[0][7].ToString()); label6.Text = ("Baza: " + dataTable.Rows[0][8].ToString()); dateTimePicker1.Value = (Convert.ToDateTime( dataTable.Rows[0][3])); textBox1.Text = dataTable.Rows[0][4].ToString(); label10.Text = dataTable.Rows[0][5].ToString(); textBox2.Text = dataTable.Rows[0][7].ToString(); textBox3.Text = dataTable.Rows[0][8].ToString(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
private void buttonCompleteOrder_Click(object sender, EventArgs e) { SqlCeCommandBuilder cmdb = new SqlCeCommandBuilder(da); string webServiceOutput; buttonCompleteOrder.Enabled = false; foreach (Seat s in selectedTable.ordered) { s.Enabled = false; } selectedTable.OrderPlaced = true; buttonStartOrder.Enabled = false; // insert into local database (TabletDatabase.sdf) ds = ldp.insertNewOrder(newOrder.OrderNo, newOrder.TableNo, ds); da.Update(ds, "Orders"); // call web services // 1. Add order to KitchenDatabase.mdf webServiceOutput = wsp.sendOrder_local(newOrder.OrderNo, newOrder.Waiter); listBoxSummary.Items.Add(webServiceOutput); // 2. Add meals in the order to KitchenDatabase.mdf Meal[] meals = newOrder.getMeals(); for (int i = 0; i < 4; i++) { wsp.sendMeal_local(meals[i].MealNo, (int)meals[i].Type, meals[i].Price, newOrder.OrderNo, (newOrder.TableNo)); } listBoxSummary.Items.Add(webServiceOutput); listBoxSummary.Items.Add("Order placed with table: " + (selectedTable.TableNo)); // The order has now been placed so clear newOrder and enable // new orders to be made newOrder = null; buttonStartOrder.Enabled = true; }
public ViewAll() { InitializeComponent(); int plainTextPasswordsFound = 0; try { string strCon = "Data Source=Accounts.sdf;Password=MySecretPassword;File Mode=Shared Read;Max Database Size=1024"; string strSQL = "SELECT * from Account"; dataAdapter = new SqlCeDataAdapter(strSQL, strCon); SqlCeCommandBuilder commandbuilder = new SqlCeCommandBuilder(dataAdapter); dt = new DataTable(); dataAdapter.Fill(dt); string tempPw = ""; foreach(DataRow row in dt.Rows){ tempPw = row["Password"].ToString(); if (tempPw.Length > 16) { row["Password"] = Decrypt.DecryptStringAES(tempPw, "waltsentme"); } else { plainTextPasswordsFound = 1; } } dbGridView2.DataSource = dt; if (plainTextPasswordsFound == 1) { warnLbl.Visible = true; } dbGridView2.Columns[0].Visible = false; dbGridView2.Columns[3].Width = 188; dbGridView2.Update(); } catch (SqlCeException ex) { MessageBox.Show(ex.Message); } }
private void car_data_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'icersDataSet.cars' table. You can move, or remove it, as needed. try { con.Open(); da = new SqlCeDataAdapter("select * from enquiry",con); SqlCeCommandBuilder cmd = new SqlCeCommandBuilder(da); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; con.Close(); } catch (Exception er) { Console.WriteLine(er.Message); } }
private void BuscarAlgoenTabla(string comando) { SqlCeConnection PathBD = new SqlCeConnection("Data Source=C:\\Facturacion\\Facturacion\\BaseDeDatos.sdf;Persist Security Info=False;"); //abre la conexion try { da = new SqlCeDataAdapter(comando, PathBD); // Crear los comandos de insertar, actualizar y eliminar SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da); dt = new DataTable(); // Llenar la tabla con los datos indicados da.Fill(dt); PathBD.Open(); } catch (Exception w) { MessageBox.Show(w.ToString()); return; } }
public Search(string searchString, string searchType) { InitializeComponent(); try { if (searchString != null) { string strCon = "Data Source=Accounts.sdf;Password=MySecretPassword;File Mode=Shared Read;Max Database Size=1024"; string strSQL = "SELECT UserName, Password, URL, HostName, ServiceName, SvcTypeName from Account WHERE " + searchType + " LIKE '%" + searchString + "%'"; dataAdapter = new SqlCeDataAdapter(strSQL, strCon); SqlCeCommandBuilder commandbuilder = new SqlCeCommandBuilder(dataAdapter); dt = new DataTable(); dataAdapter.Fill(dt); string tempPw = ""; foreach (DataRow row in dt.Rows) { tempPw = row["Password"].ToString(); if (tempPw.Length > 16) { row["Password"] = Decrypt.DecryptStringAES(tempPw, "waltsentme"); } } dbGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); dbGridView.DataSource = dt; textBox1.Text = searchString; textBox2.Text = searchType; } } catch (SqlException ex) { MessageBox.Show(ex.Message); } }
public static DataTable Databaseadapter(SqlCeDataAdapter sda , string tablename) { using(SqlCeConnection cn = new SqlCeConnection(_connstring)) { //MessageBox.Show(tablename); sda = new SqlCeDataAdapter(string.Format("SELECT * FROM {0}", tablename ), cn); sda.MissingSchemaAction = MissingSchemaAction.AddWithKey; SqlCeCommandBuilder sbuilder = new SqlCeCommandBuilder(sda); DataTable dt = new DataTable(); try { sda.Fill(dt); } catch (SqlCeException sqlex) { MessageBox.Show(sqlex.Message, "fail with filling dataset"); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { } return dt; } }
/// <summary> /// Get the info for the player out of the database and return in /// </summary> /// <param name="tag">The GamerTag of the player</param> /// <returns>PlayerInfo for the gamer</returns> private PlayerInfo GetPlayerInfo(String tag) { BattleBoatsDataSet dataset = new BattleBoatsDataSet(); PlayerInfo info = new PlayerInfo(); String select = "SELECT * FROM PlayerInfo WHERE UserName = \'" + tag + "\'"; SqlCeDataAdapter adapter = new SqlCeDataAdapter(select, conn); adapter.Fill(dataset, "PlayerInfo"); if (dataset.PlayerInfo.Rows.Count == 0)//New user, create table entries for them { BattleBoatsDataSet.PlayerInfoRow playerrow = dataset.PlayerInfo.NewPlayerInfoRow(); playerrow.UserName = tag; playerrow.AmmoUpgrades = 0; playerrow.ArmourUpgrades = 0; playerrow.Money = 0; playerrow.SpeedUpgrades = 0; playerrow.ShipModel = "Basic"; dataset.PlayerInfo.AddPlayerInfoRow(playerrow); SqlCeCommandBuilder builder = new SqlCeCommandBuilder(adapter); builder.QuotePrefix = "["; builder.QuoteSuffix = "]"; adapter.Update(dataset, "PlayerInfo"); } info.PlayerName = dataset.PlayerInfo[0].UserName; info.Ammo_Level = dataset.PlayerInfo[0].AmmoUpgrades; info.Armour_Level = dataset.PlayerInfo[0].ArmourUpgrades; info.Money = dataset.PlayerInfo[0].Money; info.Speed_Level = dataset.PlayerInfo[0].SpeedUpgrades; info.Ship_Model_Name = dataset.PlayerInfo[0].ShipModel; return info; }
public void WriteToSQL(string message, string tags, SqlCeConnection databaseConnection) { if ((_name.Length == 0) && (active == true)) { throw (new ApplicationException("Can't write to log, no name set", null)); } else { DataSet data = new DataSet(); SqlCeDataAdapter adapter = new SqlCeDataAdapter(String.Format( "SELECT * FROM {0}", _name), databaseConnection); SqlCeCommandBuilder commands = new SqlCeCommandBuilder(adapter); adapter.FillSchema(data, SchemaType.Source, _name); DataRow newRow = data.Tables[_name].NewRow(); if (message.Length > 255) { message = message.Substring(0, 255); } newRow["time"] = DateTime.UtcNow; newRow["tags"] = tags; newRow["text"] = message; data.Tables[_name].Rows.Add(newRow); adapter.Update(data, _name); } }
public static void UpdatePrefs(DataSet dataSet) { SqlCeConnection conn = BackEndUtils.GetSqlConnection(); try { SqlCeDataAdapter da = new SqlCeDataAdapter(Application_Settings_SQL.commandGetAllAppConfig, conn); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da); da.Update(dataSet); } finally { conn.Close(); } }
private void OppdaterSelgerkoder() { if (dataGridViewSk.CurrentRow == null) InitSelgerkoder(); dsSk.Clear(); conSk.Open(); if (toolStripComboBoxSkFilter.SelectedIndex > 0) daSk = new SqlCeDataAdapter("Select * from tblSelgerkoder WHERE Avdeling = '" + main.appConfig.Avdeling + "' AND Kategori = '" + toolStripComboBoxSkFilter.SelectedItem.ToString() + "'", conSk); else daSk = new SqlCeDataAdapter("Select * from tblSelgerkoder WHERE Avdeling = '" + main.appConfig.Avdeling + "'", conSk); var cmdBldr = new SqlCeCommandBuilder(daSk); daSk.Fill(dsSk, "tblSelgerkoder"); conSk.Close(); }