1 Replies - 165 Views - Last Post: 02 February 2013 - 07:23 AM Rate Topic: -----

#1 TejashreeGanesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-February 13

Update Query Unable To Run Properly

Posted 02 February 2013 - 05:50 AM

Please tell me
I have write following code for updating data as well as listview. It do not generate any error. But not updated the records in database as well as in listview also. What changes must be in my code?



 Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click
        If TxtMRNNO.Text = "" Then
            MsgBox("Please enter MRN NO. ", MsgBoxStyle.Information, "Site Management System")
            TxtMRNNO.Focus()
            Exit Sub
        End If
        'blnAddFlag = False
        'blnEditFlag = True
        '  Call SetButtons(False)
        '"insert into MRN_DTL values(" & Val(TxtMRNNO.Text) & "," & Val(Trim(ListView1.Items(i).SubItems(0).Text)) & ",'" & ListView1.Items(i).SubItems(6).Text & "'," & Val(Trim(ListView1.Items(i).SubItems(2).Text)) & "," & Val(ListView1.Items(i).SubItems(4).Text) & "," & Val(ListView1.Items(i).SubItems(5).Text) & ")"
        Dim i As Integer
        Dim strUpdate As String
        strUpdate = "update MRN_DTL  set ITEM_CODE=" & Val(ListView1.Items(i).SubItems(6).Text) & ", REQQTY=" & Val(ListView1.Items(i).SubItems(2).Text) & ", AVQTY=" & Val(ListView1.Items(i).SubItems(4).Text) & ", ORDERQTY=" & Val(ListView1.Items(i).SubItems(5).Text) & " where MRN_NO=" & Val(TxtMRNNO.Text)
        cmd.CommandText = strUpdate
        cmd.CommandType = CommandType.Text
        cmd.Connection = con
        If con.State <> ConnectionState.Open Then
            con.Open()
        End If
        i = cmd.ExecuteNonQuery
        strUpdate = "Update MRN_HEADER set MRN_DATE='" & DTMRN.Value.Date & "',SITE_CODE=" & CmbSiteName.SelectedValue & " where MRN_NO=" & Val(TxtMRNNO.Text)
        cmd.CommandText = strUpdate
        cmd.CommandType = CommandType.Text
        cmd.Connection = con
        If con.State <> ConnectionState.Open Then
            con.Open()
        End If
        i = cmd.ExecuteNonQuery
        MsgBox(i & " Reocord Updated Suucessfully!", vbExclamation, "Site Management System")
        Call ClrAll()

    End Sub



Thank You

Is This A Good Question/Topic? 0
  • +

Replies To: Update Query Unable To Run Properly

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2881
  • View blog
  • Posts: 9,559
  • Joined: 12-December 12

Re: Update Query Unable To Run Properly

Posted 02 February 2013 - 07:23 AM

I assume it is because the Date value from the DateTimePicker is not in a suitable format to directly insert into the database (depending on which database system you are using). Something like:

Dim dt As String = DTMRN.Value.ToString("yyyy-mm-dd hh:MM:ss")

INSERT INTO table (id, mytime) 
values(5, CONVERT(datetime, CONVERT( varchar(11), dt, 101))

http://msdn.microsof...y/ms187928.aspx
But you should be using prepared statements and parameters. It will be much easier to work with the date-value anyway.

This post has been edited by andrewsw: 02 February 2013 - 07:25 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1