Click here to Skip to main content
15,886,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
when I just execute this program error notification will be shown:

VB
Sub insert()
      Dim ds As New DataSet
      Dim xmlFile As XmlReader
      Dim sql As String

      Dim id As String
      Dim company As String
      Dim datecom As Date
      Dim time As String
      Dim place As String
      Dim address As String
      Dim type As String
      Dim hidden As String

      xmlFile = XmlReader.Create("../../XML/datacoba.xml", New XmlReaderSettings())
      ds.ReadXml(xmlFile)
      Dim i As Integer
      dtkoneksi.Open()
      For i = 0 To ds.Tables(0).Rows.Count - 1
          id = ds.Tables(0).Rows(i).Item(0)
          '<on this line will be shown error "cannot find column 1" >
          company = ds.Tables(0).Rows(i).Item(1)
          '</>
          datecom = (ds.Tables(0).Rows(i).Item(2))
          time = (ds.Tables(0).Rows(i).Item(3))
          place = ds.Tables(0).Rows(i).Item(4)
          address = ds.Tables(0).Rows(i).Item(5)
          type = ds.Tables(0).Rows(i).Item(6)
          hidden = ds.Tables(0).Rows(i).Item(7)
          sql = "insert into seminar_insert values(" & id & ",'" & company & "'," & datecom & "," & time & "," & place & "," & address & "," & type & "," & hidden & ")"
          'Command = New SqlCommand(sql, connection)
          cmd.CommandType = CommandType.Text
          cmd.ExecuteNonQuery()
      Next
      dtkoneksi.Close()
  End Sub

and this is xml files:
XML
<?xml version="1.0" encoding="utf-8"?>
<!--XML Files datakonsumen-->
<dataset>
    <seminar_schedule>
        <!--Start record-->
        <id>9</id>
        <company>PT rubungjaya</company>
        <date>23/05/2013</date>
        <time>01:20:00</time>
        <place>dasdas</place>
        <address>dasdas</address>
        <type>Company</type>
        <hidden>1</hidden>
        <id>13</id>
        <company>Individu</company>
        <date>14/05/2013</date>
        <time>07:23:00</time>
        <place>bandung</place>
        <address>sadasdsad</address>
        <type>Individu</type>
        <hidden>1</hidden>
        <id>14</id>
        <company>Pemkab malang</company>
        <date>21/05/2013</date>
        <time>08:12:00</time>
        <place>Gedung graha cakra</place>
        <address>Jl melati, Malang</address>
        <type>Government</type>
        <hidden>1</hidden>
        <id>15</id>
        <company>pemkot</company>
        <date>21/05/2013</date>
        <time>19:18:47</time>
        <place>hel</place>
        <address>asdasdas</address>
        <type>Government</type>
        <hidden>1</hidden>
        <id>17</id>
        <company>PT alca</company>
        <date>30/05/2013</date>
        <time>20:06:18</time>
        <place>heoeh</place>
        <address>alcaccccccc</address>
        <type>Company</type>
        <hidden>1</hidden>
        <id />
        <company />
        <date />
    </seminar_schedule>
</dataset>
Posted

1 solution

You have an improper SQL statement, if you don't specify data for EVERY column, you must identify the columns you are inserting into.

http://www.w3schools.com/sql/sql_insert.asp[^]

Otherwise how can the data driver know what columns you are trying to use?
 
Share this answer
 
Comments
Helmi Avicenna 24-May-13 23:19pm    
I mean before execute the insert query.
error message shown on this line: company = ds.Tables(0).Rows(i).Item(1)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900