title: Issue with relationship in SQL Server and Vb.net
body: <p>I have a table of &quot;CASH PAYMENT&quot;. I created two tables in SQL Server 2008 and did drag and drop in vb.net 2010.</p>
  <p>Now when I save it with default update code, I get different errors.</p>
  <p>I do not have any idea of relationships. I searched the web about it but did not find anything related to it. Also, what code can I use to update my relationship entry for vb.net using SQL Server?</p>
  <p>I tried nothing - I only drag and drop the SQL Server database in vb.net and with default update code I got error:</p>
  <blockquote>
  <p>The INSERT statement conflicted with the FOREIGN KEY constraint &quot;FK_cash-entries_cash-entries&quot;. The conflict occurred in database &quot;dbo_main&quot;, table &quot;dbo.cash_payn_details&quot;, column 'autonumber'</p>
  </blockquote>
  <p>Code is shown below. This is the default code when drag drop SQL Server in vb.net</p>
  <pre><code>Me.Validate()
      Me.Cash_payn_detailsBindingSource.EndEdit()
      Me.TableAdapterManager.UpdateAll(Me.Dbo_mainDataSet)
      Me.Cash_entriesBindingSource.EndEdit()
      Me.Cash_entriesTableAdapter.Update(Me.Dbo_mainDataSet)
  </code></pre>
  <p>I want to save two tables with one reference number. I am a beginner in vb.net and SQL Server relationships.</p>
  <h2>Edit</h2>
  <p>Table structure:</p>
  <pre><code> USE [dbo_main]
          GO
          
          /****** Object:  Table [dbo].[cash_payn_details]    Script Date: 01/04/2019 17:44:25 ******/
          SET ANSI_NULLS ON
          GO
          
          SET QUOTED_IDENTIFIER ON
          GO
          
          CREATE TABLE [dbo].[cash_payn_details](
              [autonumber] [nchar](10) NOT NULL,
              [account] [nchar](10) NULL,
              [amount] [nchar](10) NULL,
              [date] [nchar](10) NULL,
           CONSTRAINT [PK_cash_payn_details] PRIMARY KEY CLUSTERED 
          (
              [autonumber] ASC
          )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
          ) ON [PRIMARY]
          
          GO
          
          
          OTHER IS
          
          USE [dbo_main]
          GO
          
          /****** Object:  Table [dbo].[cash-entries]    Script Date: 01/04/2019 17:45:08 ******/
          SET ANSI_NULLS ON
          GO
          
          SET QUOTED_IDENTIFIER ON
          GO
          
          CREATE TABLE [dbo].[cash-entries](
              [des_autonumber] [nchar](10) NOT NULL,
              [system_ID] [nchar](10) NULL,
              [entries] [nvarchar](50) NULL,
           CONSTRAINT [PK_cash-entries] PRIMARY KEY CLUSTERED 
          (
              [des_autonumber] ASC
          )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
          ) ON [PRIMARY]
          
          GO
          
          ALTER TABLE [dbo].[cash-entries]  WITH CHECK ADD  CONSTRAINT [FK_cash-entries_cash-entries] FOREIGN KEY([system_ID])
          REFERENCES [dbo].[cash_payn_details] ([autonumber])
          GO
          
          ALTER TABLE [dbo].[cash-entries] CHECK CONSTRAINT [FK_cash-entries_cash-entries]
          GO
          
        
      
      INSERT INTO [dbo_main].[dbo].[cash-entries]
                 ([des_autonumber]
                 ,[system_ID]
                 ,[entries])
           VALUES
                 (&lt;des_autonumber, nchar(10),&gt;
                 ,&lt;system_ID, nchar(10),&gt;
                 ,&lt;entries, nvarchar(50),&gt;)
      GO
      
      
      other is
      
      INSERT INTO [dbo_main].[dbo].[cash_payn_details]
                 ([autonumber]
                 ,[account]
                 ,[amount]
                 ,[date])
           VALUES
                 (&lt;autonumber, nchar(10),&gt;
                 ,&lt;account, nchar(10),&gt;
                 ,&lt;amount, nchar(10),&gt;
                 ,&lt;date, nchar(10),&gt;)
      GO
  </code></pre>