WPF- LINQ Database doesn't update

0

Im trying to write a WPF application using Linq but while trying to update the database (add new data to it) it doesn't update at all.

I want to add another row when I click a button but it doesn't update the database at all and after checking data it's still empty.

If anyone can help me with that I would be grateful.

namespace portiEX
{

    public partial class LentPop : Window
    {
        DataBaseConnectionsDataContext DB = new DataBaseConnectionsDataContext();
        DataBaseConDataContext Con = new DataBaseConDataContext();

        DateTime CurrentDate = DateTime.Now;

        string tmp;
        List<string> EQ = new List<string>();
        public LentPop()
        {

            InitializeComponent();

            // Combobox with RoomNumbers

            List<Table_Key> dataRoom = DB.Table_Keys.ToList();

            RoomComboBox.ItemsSource = dataRoom;
            RoomComboBox.DisplayMemberPath = "ROOM_NUMBER";
            RoomComboBox.SelectedValuePath = "IDENTIFICATION_NUMBER";

            // Combobox with info who took room

            List<EMPLOYEE> dataEmp = DB.EMPLOYEEs.ToList();

            PersonBorrComboBox.ItemsSource = dataEmp;
            PersonBorrComboBox.DisplayMemberPath = "NAME_SURNAME";
            PersonBorrComboBox.SelectedValuePath = "IDENTIFICATION_NUMBER";

            // Combobox with Equipment selected

            ListEquipment();
            AddStuffComboBox.ItemsSource = EQ;

            ComboBoxsSupplement();

            //hour
            LblCurrDate.Content = CurrentDate.ToString();


        }

        private void ComboBoxsSupplement()
        {
    enter code here
            // Combobox with hours of return
            HoursLoop(HourofRetComboBox);

            // Combobox with mins of return
            MinLoop(MinsofRetComboBox);
        }

        private void ListEquipment()
        {
            foreach (var s in DB.Equipments)
            {
                if (s.QUANITY != 0)
                {
                    tmp = s.NAME;
                    EQ.Add(tmp);
                }
            }
        }
        private void CancelButt_Click(object sender, RoutedEventArgs e)
        {
            Con.Tables.InsertOnSubmit(new Table
            {
                Room_Number = decimal.Parse(RoomComboBox.Text),
                Who_Borr = PersonBorrComboBox.Text,
                Borrow_Data = CurrentDate,
                Return_Date = HourofRetComboBox.Text,
                Add_Eq = AddStuffComboBox.Text

            });
            Con.SubmitChanges();

            this.Close();
        }
        public void RentButt_Click(object sender, RoutedEventArgs e)
        {
            string x = ("Room Number: " + RoomComboBox.Text + "\nWho Borrow: " + PersonBorrComboBox.Text +
                "\nAdd Eq: " + AddStuffComboBox.Text + "\nDate: "  + LblCurrDate.Content +
                "\nReturn time: " + HourofRetComboBox.Text + ":" + MinsofRetComboBox.Text).ToString();

            DB.Borroweds.InsertOnSubmit(new Borrowed
            {
                ROOM_NUMBER = decimal.Parse(RoomComboBox.Text),
                WHO_BORROWED = PersonBorrComboBox.Text,
                ADD_EQUIPMENT = AddStuffComboBox.Text,
                BORROWED_DATE = CurrentDate.ToString(),
                RETURN_DATE = HourofRetComboBox.Text + ":" + MinsofRetComboBox.Text,
            });

            DB.SubmitChanges();
            MessageBox.Show(x);
        }
        private void HoursLoop(ComboBox comboBox)
        {
            for (int i = 0; i < 24; i++)
            {
                if(i<10)
                {
                    comboBox.Items.Add("0" + i.ToString());
                }
                else
                {
                    comboBox.Items.Add(i.ToString());
                }

            }
        }
        private void MinLoop(ComboBox comboBox)
        {
            for (int i = 0; i < 60; i++)
            {
                if(i<10)
                {
                    comboBox.Items.Add("0" + i.ToString());
                }
                else
                {
                    comboBox.Items.Add(i.ToString());
                }
            }
        }
    }
}

Database

<connectionStrings>
    <add name="portiEX.Properties.Settings.PortiEXDBsConnectionString"
        connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\PortiEXDBs.mdf;Integrated Security=True;Connect Timeout=30"
        providerName="System.Data.SqlClient" />
</connectionStrings>

@Edit After changing attach~~ to Database im getting error like that:

System.ArgumentException HResult=0x80070057 Message=Format ciągu inicjowania jest niezgodny ze specyfikacją, począwszy od indeksu 35. Source=System.Data StackTrace: at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value) at System.Data.Linq.SqlClient.SqlProvider.GetDatabaseName(String constr) at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Initialize(IDataServices dataServices, Object connection) at System.Data.Linq.DataContext.Init(Object connection, MappingSource mapping) at System.Data.Linq.DataContext..ctor(String fileOrServerOrConnection, MappingSource mapping) at portiEX.DataBaseConnectionsDataContext..ctor() in C:\Users\USER\Downloads\portiEXzDB(1)\portiEXzDB\portiEX\DataBaseConnections.designer.cs:line 54 at portiEX.LoggingPage..ctor() in C:\Users\USER\Downloads\portiEXzDB(1)\portiEXzDB\portiEX\LoggingPage.xaml.cs:line 23

This exception was originally thrown at this call stack: [External Code] portiEX.DataBaseConnectionsDataContext.DataBaseConnectionsDataContext() in DataBaseConnections.designer.cs portiEX.LoggingPage.LoggingPage() in LoggingPage.xaml.cs

c#
wpf
linq
insert-update
asked on Stack Overflow May 13, 2020 by Luke • edited May 14, 2020 by Luke

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0