I am trying to develop a project for house hold accounting.I have designed a form for transactions.Now my problem is to add the record from the form to the table when the Submit buttton is clicked.My table is "Tran" with fields-"Tdt","Achead", "Acsub","Acno","Acname"."Detail","Debit"," Credit","Dc","Balance","Tno".Record to be added to Tran where Achead,Acsub and Acno are equal to TxtAchead.Text,TxtAcsub.text, and TxtAcno.text respectively.The Balance is to be calculated by the difference of the Totals of Debit and Credit Fields and if the balance is negative field "Dc" = "DR" else "Dc" ="CR" Please help me

Recommended Answers

All 4 Replies

Can you provide what code you have so far?

 Private Sub BtnSubmit_Click(sender As Object, e As EventArgs) Handles BtnSubmit.Click
     Try
         If con.State = ConnectionState.Closed Then
             con.Open()
         End If
         Dim cmd As New OleDbCommand("INSERT INTO [Tran]([Tdt],[Achead],[Acsub],[Acno],[Acname],[Detail],[Debit],[Credit],[Tno]) VALUES(?,?,?,?,?,?,?,?,?)", con)
         cmd.Parameters.AddWithValue("@P1", TxtTdt.Text.Trim)
         cmd.Parameters.AddWithValue("@P2", TxtAchead.Text.Trim)
         cmd.Parameters.AddWithValue("@P3", TxtAcsub.Text.Trim)
         cmd.Parameters.AddWithValue("@P4", TxtAcno.Text.Trim)
         cmd.Parameters.AddWithValue("@P5", TxtAcname.Text.Trim)
         cmd.Parameters.AddWithValue("@P6", TxtDetail.Text.Trim)
         If TxtType.Text = "CR" Then
             cmd.Parameters.AddWithValue("@P7", 0)
             cmd.Parameters.AddWithValue("@P8", TxtTramt.Text.Trim)
         Else
             cmd.Parameters.AddWithValue("@P7", TxtTramt.Text.Trim)
             cmd.Parameters.AddWithValue("@P8", 0)
         End If
         cmd.Parameters.AddWithValue("@P9", TxtTno.Text.Trim)
         cmd.ExecuteNonQuery()
               LblMsg.Text = "DATA ADDED SUCCESSFULLY"
         MessageBox.Show("DATA ADDED SUCCESSFULLY", "HHA SOLUTIONS", MessageBoxButtons.OK, MessageBoxIcon.Information)
         con.Close()
         TxtMode.Enabled = True
         TxtMode.Focus()
         Clear()
         BtnSubmit.Enabled = False
     Catch ex As Exception
         MessageBox.Show(ex.Message)
         If con.State = ConnectionState.Open Then
             con.Close()
         End If
     End Try
 End Sub

The fields Dc an Balance has to be inserted.All other fields are OK

Don't use abbreviations for tables and fields. Make the names totally clear, so when you ask a friend for help, then the table and field names will be self-explanitory.

Are some of these fields calculated values? If so they can be calculated from the other values when displayed on screen.

How many tables do you think will be involved?

It's a while since I did any database work. When did you last do any database work? Because you must know how to insert into a table(s) and extract from a table(s).

And this looks like your homework, to be honest.

commented: "When I wrote this, God and I knew how it worked. Now, only God knows." +16

Thank you all .I found out the solution myself

commented: Thank God. +16
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.