2016-05-23 1 views
1

table1データをtable2にコピーしようとしている挿入クエリが1つあります。今、クエリは、私が直接MySQLの中で実行すると正常に動作しますが、私は「VB.Net経由MySQLでクエリが実行されているのに、デバッグ中にVB.NETでエラーが発生する

INSERT INTO newMedicinesOrders (`OrderID`,`medicineName`, `power`, `form`, `fQuantity`, `iQuantity`, `type`, `cost`, `prescriptionLink`, `userID`) SELECT `orderID`, `name`, `power`, `form`, `fQuantity`, `iQuantity`, `type`, `mrp`, `prescriptionLink`, `userID` from myCart WHERE userID = '1' 

をデバッグしようとしたとき、私は「フィールドリストに

不明な列を 『のorderID』というエラーメッセージが表示されます「

VBコード

Try 
      Dim str1 As String = "INSERT INTO newMedicinesOrders (`OrderID`,`medicineName`, `power`, `form`, `fQuantity`, `iQuantity`, `type`, `cost`, `prescriptionLink`, `userID`) SELECT `orderID`, `name`, `power`, `form`, `fQuantity`, `iQuantity`, `type`, `mrp`, `prescriptionLink`, `userID` from myCart WHERE userID = '" + userid.Text + "'" 

      Dim str2 As MySqlDataReader 
      Dim adapter As New MySqlDataAdapter 
      Dim command As New MySqlCommand 
      command.CommandText = str1 
      command.Connection = con 
      adapter.SelectCommand = command 
      con.Open() 
      str2 = command.ExecuteReader 
      con.Close() 
      Response.Write("<script language='javascript'>alert('Success.');</script>") 
     Catch ex As Exception 
      Response.Write(ex) 
     End Try 
+0

@eggyal「フィールドリスト」で「未知の列 'orderID'」と表示されます。 –

+0

このクエリを呼び出すコードはvb 。ネット? – eggyal

+0

@eggyalデバッグモードのスクリーンショットを表示しても問題ありませんか? –

答えて

0

私はあなたのエラーが事実から来ていると信じてあなたはthis descriptionからSQLCommand.ExecuteReader()

を使用していること:DataReaderオブジェクトとしてクエリ結果を取得するために使用

のExecuteReader。これは、レコードの読み取りのみを転送するreadonlyであり、最初から最後までテーブルを読み取るためにselectコマンドを使用します。

ExecuteNonQueryデータを返さないクエリの実行に使用されます。これは、update、insert、deleteなどのSQL文を実行するために使用されます。ExecuteNonQueryは、コマンドを実行し、影響を受ける行の数を返します。

MSDNによると、これはあなたがINSERTUPDATEまたはDELETE文を実行する方法である:

Public Sub CreateCommand(ByVal queryString As String, ByVal connectionString As String) 
    Using connection As New SqlConnection(connectionString) 
     Dim command As New SqlCommand(queryString, connection) 
     command.Connection.Open() 
     command.ExecuteNonQuery() 
    End Using 
End Sub 

あなたがExecuteReader()を使用してINSERTコマンドを実行するときしかし、私は何が起こるかについての情報を見つけることができませんでしたが、私はそれが起こると思います...

関連する問題