Link to home
Start Free TrialLog in
Avatar of lion79
lion79

asked on

how to make a calculated field save into sql table?

Hi,
I have a form that has input,used and output,the output is a calculated field that i don't show in the form but i have it in my sql table,the user inserts output and used and i want to be able to calculate the output and save itdirectly to my sql table
i thought of doing a hidden field that reads from the input and used and then calculate it as follows:
output=input - used

but i don't know how to read from the fields ,below is my insert code:
*************************************************************************
Try
  Dim MySQL As String = "Insert into totals(input,used) values(@txttext1,@texttest2)"

 Dim myConn As SqlConnection = New SqlConnection("data source=dcmp;uid=sa;pwd=;database=bookshop")
            Dim Cmd As New SqlCommand(MySQL, myConn)
            Cmd.Parameters.Add(New SqlParameter("@txttext1", TextBox1.Text))
            Cmd.Parameters.Add(New SqlParameter("@texttest2", TextBox2.Text))


End Try
        BindData()
        'myConn.Close()

    End Sub

    Sub BindData()

        'Dim MySQL as string = "Select * from totals where [bookid] = @id"
        Dim myConn As SqlConnection = New SqlConnection("data source=dcmp;uid=sa;pwd=;database=bookshop")
        Dim MySQL As String
        MySQL = "Select * from totals order by dbookid "
        Dim Cmd1 As New SqlCommand(MySQL, myConn)
        'cmd1.Parameters.Add(New SqlParameter("@id", tmstm.text))

        Dim ds As DataSet = New DataSet
        Dim Cmd As New SqlDataAdapter(MySQL, myConn)
        Cmd.Fill(ds, "totals1")
        mydatagrid.DataSource = ds.Tables("totals1").DefaultView
        mydatagrid.DataBind()
***********************************************************************************

is it the right way to use hidden textbox or there is better way?
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial