SqlCe Insert / Replace NText Problem

B

Boas Enkler

Hi

I've got an really strange and awfull problem with inserts and updates into
the SQLCe Server concerning memo fields.

I've got an SqlCe Command with parameters.

For Example this definition of one command.:

this.SaveStaCmd = new SqlCeCommand("insert into table1(ID,MyText)
values(?,?)",program.oDaten.sqlConn);

this.SaveStaCmd.Parameters.Add(new SqlCeParameter("ID", SqlDbType.NChar,
10));
this.SaveStaCmd.Parameters.Add(new SqlCeParameter("MyText",
SqlDbType.NText));
try
{
this.SaveStaCmd.Prepare();
}
catch(SqlCeException oErr)
{
MessageBox.Show(oErr.Message);
}

I execute the command like this:

this.SaveStaCmd.Parameters["ID"].Value = " 1";
this.SaveStaCmd.Parameters["MyText"].Value = "My Data Test"
try
{
this.SaveStaCmd.ExecuteNonQuery();
}
catch(SqlCeException oErr)
{
MessageBox.Show(oErr.Message);
}


Now everytime when I set the parameters and run ExecuteNoQuery() the
Memofield is blank, although the SqlCe parameter is correctly filled.

This only happens when the command is executed for the first time. When I
run for example the command with dummy data (or run the statement twice)
beforw, then all following inserts / replaces after the first will work.
Only the first Insert / Replace lefts the NText field empty. All other
fields are filled correctly.

This is also true for replaces.
I got this problem with each insert and replace SqlCe command.
When I take the SqlCe Command and run it via the SqlCe Query Analyzer
everything works fine.
In the debugger I can see that the SqlCeParameter has the correct value
before and after ExecuteNonQuery() but in the DB the field is empty.

Can anyone give me an hint?
I've no Idea on how to solve this, and making an dummy inserts / replace
for each command which includes an NText field when its first time executed
isn't a good way

Thanks in advance
Boas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top