Windows Develop Bookmark and Share   
 index > Windows Forms General > incorrect synatx near keyword where
 

incorrect synatx near keyword where

Hi all,

Here is the my coding:-

Dim con As New SqlConnection
con.ConnectionString = "server=empd-ip;database=EMPD_nameplate;uid=sa;pwd=empdbluffton"
Dim sql As String
sql = " select Modelno,rev from HzModelData"
Dim dt As New DataTable
Dim adp As New SqlDataAdapter(sql, con)
con.Open()
adp.Fill(dt)
If dt.Rows.Count > 0 Then
Dim row As DataRow
For Each row In dt.Rows
Dim model As String = row.Item(0).ToString
Dim rev As Integer = CInt(row.Item(1).ToString)
sql = " select * from HzModeldata where Modelno='" & model & "' and rev=" & rev & " and Hz=50 "
Dim adpsub As New SqlDataAdapter(sql, con)
Dim dtsub As New DataTable
adpsub.Fill(dtsub)
If dtsub.Rows.Count > 0 Then
Dim rowsub As DataRow
For Each rowsub In dtsub.Rows
Dim modelno As String = rowsub.Item(0).ToString
Dim rev1 As Integer = CInt(rowsub.Item(1).ToString)
Dim Volts As String = rowsub.Item(2).ToString
Dim KW As String = rowsub.Item(3).ToString
Dim Cos As String = rowsub.Item(4).ToString
Dim FLa1 As String = rowsub.Item(5).ToString
Dim FLA2 As String = rowsub.Item(6).ToString
Dim MA As String = rowsub.Item(7).ToString
Dim Hp1 As String = rowsub.Item(8).ToString
Dim Hp2 As String = rowsub.Item(9).ToString
Dim rpm1 As String = rowsub.Item(10).ToString
Dim rpm2 As String = rowsub.Item(11).ToString
Dim sf As String = rowsub.Item(12).ToString
Dim sfa1 As String = rowsub.Item(13).ToString
Dim sfa2 As String = rowsub.Item(14).ToString
sql = "insert into HzModeldata_New(Hz50,Volts50,KW50,Cos50,Fla_Hi50,Fla_Lo50,MaxAmps50,Hp_Hi50,Hp_Lo50,RPM_Hi50,RPM_Lo50,SF50,SFA_Hi50,SFA_Lo50) values(@hz,@v,@kw,@c,@f1,@f2,@ma,@h1,@h2,@r1,@r2,@s,@sf1,@sf2) where modelno='" & modelno & "' and rev=" & rev1
adp.Dispose()
adpsub.Dispose()
Dim cmd As New SqlCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = sql
cmd.Connection = con
cmd.Parameters.Add("@hz", SqlDbType.Int).Value = 50
cmd.Parameters.Add("@v", SqlDbType.VarChar, 25).Value = Volts
cmd.Parameters.Add("@kw", SqlDbType.VarChar, 10).Value = KW
cmd.Parameters.Add("@c", SqlDbType.VarChar, 10).Value = Cos
cmd.Parameters.Add("@f1", SqlDbType.VarChar, 20).Value = FLa1
cmd.Parameters.Add("@f2", SqlDbType.VarChar, 20).Value = FLA2
cmd.Parameters.Add("@ma", SqlDbType.VarChar, 20).Value = MA
cmd.Parameters.Add("@h1", SqlDbType.VarChar, 20).Value = Hp1
cmd.Parameters.Add("@h2", SqlDbType.VarChar, 20).Value = Hp2
cmd.Parameters.Add("@r1", SqlDbType.VarChar, 20).Value = rpm1
cmd.Parameters.Add("@r2", SqlDbType.VarChar, 20).Value = rpm2
If sf = "" Then
cmd.Parameters.Add("@s", SqlDbType.Float).Value = System.DBNull.Value
Else
cmd.Parameters.Add("@s", SqlDbType.Float).Value = sf

End If
cmd.Parameters.Add("@sf1", SqlDbType.VarChar, 20).Value = sfa1
cmd.Parameters.Add("@sf2", SqlDbType.VarChar, 20).Value = sfa2
cmd.ExecuteNonQuery()
cmd.Dispose()


Next

End If

Next

End If

con.Close()
MsgBox("Yes")
End Sub

And I am getting this error:-

"incorrect syntax near keyword where"

schauhan  Wednesday, August 19, 2009 2:03 PM
There are 2 wheres, which one?

But I guess it's the second one. There is no point in defining a WHERE when you are inserting. That is only available on updates and deletes.
Geert van Horrik - CatenaLogic
Visit my blog: http://blog.catenalogic.com

Looking for a way to deploy your updates to all your clients? Try Updater!
Geert van Horrik  Wednesday, August 19, 2009 2:07 PM
There are 2 wheres, which one?

But I guess it's the second one. There is no point in defining a WHERE when you are inserting. That is only available on updates and deletes.
Geert van Horrik - CatenaLogic
Visit my blog: http://blog.catenalogic.com

Looking for a way to deploy your updates to all your clients? Try Updater!
Geert van Horrik  Wednesday, August 19, 2009 2:07 PM
Thank you Sir
schauhan  Wednesday, August 19, 2009 2:12 PM

You can use google to search for other answers

Custom Search

More Threads

• Windows Service & Form...
• C# - Retrieve master list from SQL Server and pass it to Combo Box
• Toolbar - Toolstrip
• Disable datasource creation when adding a web reference
• How to Fire events to the parent form?
• Changing Border Color of a Button every 3 seconds
• Preferences Manager
• MDI Validating
• Datagridview
• fill a panel with a form/dialog