Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
connect()
Dim num = DataGridView1.RowCount
num = num - 1
For i As Integer = 0 To num
Dim c1 = DataGridView1.Rows(i).Cells(0).Value
Dim c2 = DataGridView1.Rows(i).Cells(1).Value
Dim c3 = DataGridView1.Rows(i).Cells(2).Value
Dim c4 = DataGridView1.Rows(i).Cells(3).Value
Dim c5 As String = Date.Now.ToString("yyyyMMdd")
Dim c6 As String = Date.Now.ToString("hhmmss")
Dim c7 As String = Date.Now.ToString("yyyyMMdd")
Dim c8 As String = Date.Now.ToString("hhmmss")
sql = String.Format("Select Count (*) as QTY from Import where Country" = c1 And "[First Date]" = c2 And "[Final Date]" = c3)
If "QTY" <> 0 Then
sql = String.Format("Update Import SET Country " = c1, "[First Date]" = c2, "[Final Date] " = c3, "[Exchange Rate]" = c4, "[Update Date]" = c7, "[Update Time]" = c8)
Else
sql = String.Format("Insert into import values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')",
c1, c2, c3, c4, c5, c6, c7, c8)
End If
cmd = New SqlCommand(sql, cn)
cmd.ExecuteNonQuery()
Next
MsgBox("Saved successfully")
End Sub
Tag : .NET, Ms SQL Server 2008, VBScript, Win (Windows App), VS 2010 (.NET 4.x)
Dim _QTY As Integer
Dim sql As String
sql = "5555 SQL 5555"
Using con As New SqlConnection(connStr)
Using com As New SqlCommand(sql, con)
con.Open()
_QTY= Convert.ToInt32(com.ExecuteScalar())
End Using
End Using
If _QTY <> 0 Then
sql = Update Data 555
Else
sql = Insert DATA 5555
End If
cmd = New SqlCommand(sql, cn)
cmd.ExecuteNonQuery()
Using cn As New SqlConnection("connectionstring")
Using com As New SqlCommand(sql, cn)
cmd = New SqlCommand(sql, cn)
cn.Open()
_QTY = Convert.ToInt32(cmd.ExecuteScalar())
End Using
End Using
ผมใส่แบบนี้แล้วมี error แจ้งว่า Could not find stored procedure 'False'. ตรง _QTY = Convert.ToInt32(cmd.ExecuteScalar())
อะครับ ขอโทษทีครับ ผมมันไม่เอาไหน ช่วยด้วยยย