Aries.ektf.hu



using access data source….filenew (WPF app)XAML code Server ExplorerCreate a new access database fileAdd a new exiting item (filter is *.*)BrowseHow to catch the connection string…using System.Data and System.Data.OleDbxaml code:<Window x:Class="database_accessDataSource.MainWindow" xmlns="" xmlns:x="" Title="database1" Height="350" Width="525"> <StackPanel> <StackPanel Orientation="Horizontal"> <Label Content="Name: "/> <TextBox x:Name="tbName" Width="100"/> <Label Content="E-mail: "/> <TextBox x:Name="tbEmail" Width="100"/> <Button x:Name="btnIns" Width="100" Content="Insert" Click="btnIns_Click"/> </StackPanel> <DataGrid x:Name="dtG" ItemsSource="{Binding}"/> </StackPanel></Window>cs code:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using System.Data;using System.Data.OleDb;namespace database_accessDataSource{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\users\user\documents\visual studio 2013\Projects\database_accessDataSource\database_accessDataSource\datas.accdb"); public MainWindow() { InitializeComponent(); GetData(); } private void GetData() { DataTable dt = new DataTable(); try { con.Open(); string sqlQuery = "SELECT * FROM [users]"; OleDbDataAdapter da = new OleDbDataAdapter(sqlQuery, con); da.Fill(dt); dtG.DataContext = dt; con.Close(); } catch { MessageBox.Show("Connection error"); } } private void Insertion(string name,string email) { OleDbCommand command = new OleDbCommand(); mandText = "INSERT INTO [users] (user_name, user_email) VALUES ('" + name + "', '" + email + "')"; mandType = CommandType.Text; command.Connection = con; try { con.Open(); command.ExecuteNonQuery(); con.Close(); } catch (Exception) { MessageBox.Show("Connection error"); } } private void btnIns_Click(object sender, RoutedEventArgs e) { Insertion(tbName.Text, tbEmail.Text); GetData(); } } } ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download