none
Save Record To Access Database RRS feed

  • Question

  • Hi,

    I thought I had what would be a simple access database, 2 tables joined on an ID field. I dragged the M1 fields onto my form main tab, i dragged the M2 onto tab 2 as a datagridview

    I created the datasets with the designer in the DataSources tab.

    I am looping through a text file line by line that has the main group of fields and a sub group of fields.

    M1_fld1      Join field

    M3_fld2

    M1_fld3

         M2_fid1

         M2_fld2   joined 1 to many with M1_fld1

         M2_fld3

    The import of the M1 is working fine all fields in the M1 section are populated as expected and the record is saved to the database.

    The import of the M2 imports into the dgv fine, however the M2 records are not saved in the database.

    Sorry I can't provide and code atm, just wondering if its something simple

    Thank You

    MW

    Tuesday, July 2, 2019 1:48 PM

All replies

  • Hi,

    Maybe you can try to update the data in the database using "SqlCommandBuilder".

        SqlDataAdapter adapter = null;
        DataSet dSet = null;
        private static string strConn = "connection string";
        private void Form3_Load(object sender, EventArgs e)
        {
            adapter = new SqlDataAdapter("select * from UserInfo", strConn);
            dSet = new DataSet();
            adapter.Fill(dSet);
            DGVMain.DataSource = dSet.Tables[0];
        }
        private void button1_Click(object sender, EventArgs e)
        {
            SqlCommandBuilder scb = new SqlCommandBuilder(adapter);
            try
            {
                adapter.Update(dSet);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 3, 2019 5:37 AM
    Moderator
  • Howdy,

    I did manage to get it working using the SQL commands.

    I do have a question about field lengths, I have a field that it keeps saying is not long enough. What controls the field lengths? Is it the database itself or does the table in datasource designer overrule the database? And I suppose the fields on the form also could have a length.

    Thanks

    MW

    Wednesday, July 3, 2019 2:23 PM
  • Hi,

    Each field has the length limit. For more info, you can refer to this document.

    Data types (Transact-SQL).

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 4, 2019 5:21 AM
    Moderator