G
Guest
I am having a problem pulling in XML data into a PPC Compact .NET app and
saving it to a SQL CE .SDF file. I get an error message that is simply the
name of the first column. I have checked everything I can think of to no
avail.
My steps in the code:
- Create a connection to the SQL CE .SDF file
- Create a command for table direct access to the main table
- Create a data adapter from the command
- Create a data set
- Read in the XML schema from the XML schema file I created on the desktop
- Create a command for an insert and store it to the data adapter insert
command
- Add all the necessary parameters using the correct data types
- Do a DataAdapter.Update(DataSet, "Table")
On this command is where I get my exception. The message is simply the name
of the first column.
What am I doing wrong???????
---------------------------------------------------------------------------------------
Here is the code. I stripped out all the error checking and such. Also, note
I am reusing the Command object and just reseting the properties to what I
need.
cn = New SqlCeConnection("Data Source=\My Documents\emsw.sdf;Password=")
cn.Open()
cmd = cn.CreateCommand
cmd.CommandText = "People"
cmd.CommandType = CommandType.TableDirect
daPeople = New SqlCeDataAdapter(cmd)
Dim ds As New DataSet("LoadTables")
ds.ReadXmlSchema(DataSchema)
cmd.CommandType = CommandType.Text
cmd.CommandText = "INSERT INTO people " & _
"(RegistrationNumber, LastName, FirstName, MiddleInitial, LocalUnion, "
& _
" Address, State, ZipCode, PhoneNumber) " & _
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
cmd.Parameters.Add("RegistrationNumber", SqlDbType.Int)
cmd.Parameters.Add("LastName", SqlDbType.NChar)
cmd.Parameters.Add("FirstName", SqlDbType.NChar)
cmd.Parameters.Add("MiddleInitial", SqlDbType.NChar)
cmd.Parameters.Add("LocalUnion", SqlDbType.Int)
cmd.Parameters.Add("Address", SqlDbType.NChar)
cmd.Parameters.Add("State", SqlDbType.NChar)
cmd.Parameters.Add("ZipCode", SqlDbType.Int)
cmd.Parameters.Add("PhoneNumber", SqlDbType.NChar)
daPeople.InsertCommand = cmd
daPeople.Update(ds, "People") <----------------------- Error happens
here
ds.Tables("People").AcceptChanges()
saving it to a SQL CE .SDF file. I get an error message that is simply the
name of the first column. I have checked everything I can think of to no
avail.
My steps in the code:
- Create a connection to the SQL CE .SDF file
- Create a command for table direct access to the main table
- Create a data adapter from the command
- Create a data set
- Read in the XML schema from the XML schema file I created on the desktop
- Create a command for an insert and store it to the data adapter insert
command
- Add all the necessary parameters using the correct data types
- Do a DataAdapter.Update(DataSet, "Table")
On this command is where I get my exception. The message is simply the name
of the first column.
What am I doing wrong???????
---------------------------------------------------------------------------------------
Here is the code. I stripped out all the error checking and such. Also, note
I am reusing the Command object and just reseting the properties to what I
need.
cn = New SqlCeConnection("Data Source=\My Documents\emsw.sdf;Password=")
cn.Open()
cmd = cn.CreateCommand
cmd.CommandText = "People"
cmd.CommandType = CommandType.TableDirect
daPeople = New SqlCeDataAdapter(cmd)
Dim ds As New DataSet("LoadTables")
ds.ReadXmlSchema(DataSchema)
cmd.CommandType = CommandType.Text
cmd.CommandText = "INSERT INTO people " & _
"(RegistrationNumber, LastName, FirstName, MiddleInitial, LocalUnion, "
& _
" Address, State, ZipCode, PhoneNumber) " & _
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
cmd.Parameters.Add("RegistrationNumber", SqlDbType.Int)
cmd.Parameters.Add("LastName", SqlDbType.NChar)
cmd.Parameters.Add("FirstName", SqlDbType.NChar)
cmd.Parameters.Add("MiddleInitial", SqlDbType.NChar)
cmd.Parameters.Add("LocalUnion", SqlDbType.Int)
cmd.Parameters.Add("Address", SqlDbType.NChar)
cmd.Parameters.Add("State", SqlDbType.NChar)
cmd.Parameters.Add("ZipCode", SqlDbType.Int)
cmd.Parameters.Add("PhoneNumber", SqlDbType.NChar)
daPeople.InsertCommand = cmd
daPeople.Update(ds, "People") <----------------------- Error happens
here
ds.Tables("People").AcceptChanges()