|
|
|
ถ้ามี ID แล้วให้ update แต่ถ้าไม่มีให้ Insert ขอความช่วยเหลือหน่อยครับ |
|
|
|
|
|
|
|
พอดีมีปัญหานิดหน่อยครับ คือโค๊ดมันรันไม่ถึง Else อ่ะครับไม่รู้ว่าผิดตรงไหน แก้จนตันแล้ว วอนผู้รู้ช่วยแก้ทีครับ
Code (VB.NET)
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim objConn As New MySqlConnection
Dim objCmd As New MySqlCommand
Dim strConnString, strSQL As String
Me.IDM.Text = Session("strUser").ToString
Dim intNumRows As Integer
strConnString = "Server=localhost;User Id=root; Password=1234; Database=feederphone; Pooling=false"
Dim Con As New MySqlConnection(strConnString)
strSQL = "SELECT * FROM feeder_sched WHERE (KeyID like '%" & IDM.Text & "%' ) "
Con.Open()
Dim Command As New MySqlCommand(strSQL, Con)
Try
intNumRows = Command.ExecuteScalar
Catch ex As Exception
MsgBox("Error")
End Try
If intNumRows = 0 Then
strSQL = "INSERT INTO feeder_sched (hour_1,min_1,hour_2,min_2,hour_3,min_3,weight_1,weight_2,weight_3,KeyID) " & _
" VALUES " & _
" ('" & Me.Hour1.Text & "','" & Me.Min1.Text & "', " & _
" '" & Me.Hour2.Text & "','" & Me.Min2.Text & "','" & Me.Hour3.Text & "','" & Me.Min3.Text & "','" & Me.weight1.Text & "','" & Me.weight2.Text & "','" & Me.weight3.Text & "','" & Me.IDM.Text & "')"
objConn.ConnectionString = strConnString
objConn.Open()
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Try
objCmd.ExecuteNonQuery()
Me.Label10.Visible = True
Me.Label10.Text = "Success Set Time"
Catch ex As Exception
Me.Label10.Visible = True
Me.Label10.Text = "Failed Please press Update"
End Try
objConn.Close()
objConn = Nothing
Else
strSQL = "UPDATE feederphone.feeder_sched SET hour_1='" & Hour1.Text & "',min_1='" & Min1.Text & "',hour_2='" & Hour2.Text & "',min_2='" & Min2.Text & "',hour_3='" & Hour3.Text & "',min_3='" & Min3.Text & "',weight_1='" & weight1.Text & "',weight_2='" & weight2.Text & "',weight_3='" & weight3.Text & "',KeyID='" & IDM.Text & "' WHERE KeyID = '" & IDM.Text & "'"
objConn.ConnectionString = strConnString
objConn.Open()
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Try
objCmd.ExecuteNonQuery()
Me.Label10.Visible = True
Me.Label10.Text = "Updated"
Catch ex As Exception
Me.Label10.Visible = True
Me.Label10.Text = "Failed Please check you NetWork"
End Try
objConn.Close()
objConn = Nothing
End If
End Sub
Tag : .NET, MySQL, VB.NET
|
ประวัติการแก้ไข 2017-02-06 02:46:29 2017-02-06 02:49:31
|
|
|
|
|
Date :
2017-02-05 23:59:25 |
By :
kosspeed |
View :
758 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แนะนำให้เอา try ออกไปก่อนครับ
จะได้รู้มันติดอยู่ตรงไหน
|
|
|
|
|
Date :
2017-02-06 08:31:37 |
By :
lamaka.tor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มี Tools ที่สุดยอดอย่าง Visual Studio ก็ให้ Debug ดูเลยครับ
|
|
|
|
|
Date :
2017-02-06 11:14:27 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้ได้แล้วครับผม แค่ต้องเปลี่ยนการรับค่าของ Excutescalar ให้เป็น String
|
|
|
|
|
Date :
2017-02-07 01:26:48 |
By :
kosspeed |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2017-02-07 11:22:24 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|