Click here to Skip to main content
15,883,990 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to find out best practises on updating particular row columns based on my vb.net form.

With my form, what happens is you click on a combobox which is bound to an RA column.
It then reads the row information and places that into the textboxes on the form.

This is for a repairs database, so basically I can't update all of the information straight away, as I won't be sure if I will have all the information straight away. E.G

I have a our cost field and a customer cost field, quote checkbox and accept checkbox.

I will be able to fill out the our cost, customer cost and quote fields, but I can't do the accept checkbox, as I haven't sent it to the customer as yet.

The only way I can think of doing this at the moment is to have a separate function for each field depending on whether that field is populated, or nothing.
E.G If our_cost .text isnot nothing then
- Do query (update row where ra = "x" -
If accept.checked = true then
- do query -

But, this does require a lot of separate functions and sql statements within the program and I would only be updating one column at a time. I'm thinking there must be a better way.

And also, When I do go into flag that accept checkbox - I don't particularly need it to update the columns of information since they've already been updated. Should I just update the entire row, or is there a way to say if textbox = same as column, do nothing?
Posted
Comments
[no name] 16-Sep-14 10:02am    
It would really help if you posted the code you have so far with detailed explanations for each line as to what you want it to do.
Mendaharin 18-Sep-14 1:43am    
I haven't written the whole statement yet (I am having trouble writing the Update statement...) But, below is what I think I can get done. But as I said, I don't think it's "correct"



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Each Dim is a separate input. Sometimes they will be typed into, othertimes they won't. I want to be able to update the row's column, only if it's required.

Dim ourcost As Double = CDbl(Our_CostTextBox.Text)
Dim quote As Boolean = QuoteCheckBox.Checked
Dim accept As Boolean = AcceptCheckBox.Checked
Dim price As Double = CDbl(PriceTextBox.Text)
Dim fixcon As String = FixConTextBox.Text
Dim ra As String = RA_IDComboBox.Text
' The only way I can think of how to do this, is if statements for each variable. And to check that the variable has something in it. But, if it already has a value in it, I don't want it to update.

If ourcost >= 0 Then
ourcostsub(ra, ourcost)
End If

'My dodgey update statement, I'm currently just getting my head around how to work with the data, so I'm aware of SQL parameters to stop injection, but I just want to get something working for now so I understand, and then once I've done that go through and fix the code up.

sub ourcostsub(byval ra as string, byval ourcost as Double)
" update RA(our_cost) " & _
" Set ( " & _
"'" & ourcost & "'" & _
" Where(RA_ID = '" & ra & "')"
Mendaharin 18-Sep-14 2:50am    
:) I got my update statement properly...Besides not using sql parameters.. i'll get that bit done shortly.

Dim insertqry As String = " update RA " & _
" Set our_cost = " & _
"'" & ourcost & "'" & _
" Where RA_ID = '" & ra & "'"
Dim sqlconnection As New SqlConnection(Main.connectionstring)
Dim command As New SqlCommand(insertqry, sqlconnection)

Try
SqlConnection.Open()
command.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
Finally
SqlConnection.Close()
End Try

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900