1.11M Members

Update one column with multiple values from multiple text box

 
0
 

hi can someone please help me in updating one column in a table but you will be using three values from a textbox..
it was like this.

    tablebook
    column  in tablebook is quantity
i need to update a book quantity using the value from textbox1. but
wat if i have a value from textbox2 and textbox3
i need to update textbox1,textbox2,textbox3 values into book quantity where it has different bookname

sample of my coding

If TextBox1.Text <> "" And TextBox2.Text <> "" And TextBox4.Text <> "" Then
            SqlCon.Open()
            sqlCommand.Connection = SqlCon
            sqlCommand.CommandText = "UPDATE books SET quantity = " & qt1.Text - 1 & " WHERE book_ID = '" & TextBox1.Text & "'"
            sqlCommand.ExecuteNonQuery()
            SqlCon.Close()
            update_quantity_borrow()
            SqlCon.Open()
            sqlCommand.CommandText = "UPDATE books SET quantity = " & q2.Text - 1 & " WHERE book_ID = '" & TextBox2.Text & "'"
            sqlCommand.ExecuteNonQuery()
            SqlCon.Close()
            update_quantity_borrow()
            SqlCon.Open()
            sqlCommand.CommandText = "UPDATE books SET quantity = " & q3.Text - 1 & " WHERE book_ID = '" & TextBox4.Text & "'"
            sqlCommand.ExecuteNonQuery()
            SqlCon.Close()
            update_quantity_borrow()
        End If
 
0
 

can you please explain little bit , ?what you want to do ? may be we can give to better solution .

Regards

 
0
 

Maybe I'm reading this wrong, but you'll have multiple rows, each with a book and a possible Quantity. you want the user to hit Update once and it will update each Row with the Quantity if it exists?

If that's correct, why not just do a Loop through the Rows, for each Row, if txtQty > 0 then Update based on current RowID ?

Also, they way you are performing your SQL Querys is a huge no-no, it's begging for SQL injection and a Hack!

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article