Updation problem
-
What is error in this code? When I click btnsave button, though it is giving the message 'Project has been started', the data is not getting updated. Protected Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click start(txtpno.Text.Trim()) End Sub Function start(ByVal pno As String) Dim sqlstr1 As String Dim dr As SqlClient.SqlDataReader sqlstr1 = "update D_task_det set str_date='" & Now.Date() & "',status='In_Progress' where pno='" & pno & "'and flag='0'and task='" & lbltask.Text.Trim() & "' and status='Pending'" Try If dbconn.State <> ConnectionState.Open Then dbconn.Open() End If Dim sqlcomm1 As New SqlClient.SqlCommand(sqlstr1, dbconn) sqlcomm1.ExecuteNonQuery() dbconn.Close() lblmsg.ForeColor = Drawing.Color.DarkGreen lblmsg.Text = "Project has been started." tbentervalue.Visible = False tbtelescopic.Visible = False tbpto.Visible = False tbsystem.Visible = False tbaccessories.Visible = False tbvalves.Visible = False tbpumps.Visible = False tbtipper.Visible = False tbentervalue.Visible = False tboth.Visible = False lbltask.Visible = False ' clear() newproject() Catch ex As Exception lblmsg.Text = "Transaction failed." ' + ex.ToString() dbconn.Close() End Try End Function
Chaitra N
-
What is error in this code? When I click btnsave button, though it is giving the message 'Project has been started', the data is not getting updated. Protected Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click start(txtpno.Text.Trim()) End Sub Function start(ByVal pno As String) Dim sqlstr1 As String Dim dr As SqlClient.SqlDataReader sqlstr1 = "update D_task_det set str_date='" & Now.Date() & "',status='In_Progress' where pno='" & pno & "'and flag='0'and task='" & lbltask.Text.Trim() & "' and status='Pending'" Try If dbconn.State <> ConnectionState.Open Then dbconn.Open() End If Dim sqlcomm1 As New SqlClient.SqlCommand(sqlstr1, dbconn) sqlcomm1.ExecuteNonQuery() dbconn.Close() lblmsg.ForeColor = Drawing.Color.DarkGreen lblmsg.Text = "Project has been started." tbentervalue.Visible = False tbtelescopic.Visible = False tbpto.Visible = False tbsystem.Visible = False tbaccessories.Visible = False tbvalves.Visible = False tbpumps.Visible = False tbtipper.Visible = False tbentervalue.Visible = False tboth.Visible = False lbltask.Visible = False ' clear() newproject() Catch ex As Exception lblmsg.Text = "Transaction failed." ' + ex.ToString() dbconn.Close() End Try End Function
Chaitra N
You should read up on SQL injection attacks. Nowhere does your code check to see if the update command actually updated any records, I recommend stepping through to see what the sQL is, and running the same SQL in query analyser, to see if it actually finds any records to update.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
You should read up on SQL injection attacks. Nowhere does your code check to see if the update command actually updated any records, I recommend stepping through to see what the sQL is, and running the same SQL in query analyser, to see if it actually finds any records to update.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
When I run the statement in query analyzer, it does work. And how to read up on SQL injection attacks
Chaitra N