|
-
Jun 5th, 2007, 05:14 AM
#1
Thread Starter
Junior Member
Cannot generate an updatable cursor for the query because there is no updatable colu
i have a problem when i try to export from sql mobile to xml .I keep getting this error Cannot generate an updatable cursor for the query because there is no updatable column [ Cursor Option = 2 ].
Code:
StreamWriter sw = File.CreateText(@"\Program Files\ContorPDA\Aparate.xml");
string result = string.Empty;
string res = string.Empty;
result += "<?xml version='1.0'?>" + "\r\n";
result += "<Aparate>" + "\r\n";
sw.Write(result);
SqlCeCommand cmd = Biblio.pCon.CreateCommand();
cmd.CommandText = "SELECT '<Aparat Id=\"'+ CONVERT(nvarchar,id) + '\" Denumire=\"' + Denumire + " +
" '\" NumarCitire=\"' + NumarCitire + " +
" '\" DataCitire=\"' + CONVERT(nvarchar,DataCitire) + " +
" '\" ContorGeneralInitial=\"' + ContorGeneralInitial + " +
" '\" ContorGeneralFinal=\"' + ContorGeneralFinal +'\" Partener=\"' + Partener + '\" >', Aparat.id" +
" FROM Aparat ";
SqlCeResultSet scrs = cmd.ExecuteResultSet(ResultSetOptions.Scrollable);
while (scrs.Read())
{
result = String.Empty;
result += scrs.GetValue(0) + "\r\n";
SqlCeCommand cmdP = Biblio.pCon.CreateCommand();
cmdP.CommandText = "SELECT '<Pozitie Id=\"' + CONVERT(nvarchar,id) + '\" id_aparat=\"' + CONVERT(nvarchar,id_aparat) + " +
" '\" ContorInitial=\"' + ContorInitial + '\" ContorFinal=\"' +ContorFinal + '\" Produs=\"' + Produs +'\"/>' FROM Prodaparat WHERE Prodaparat.id_aparat=" + scrs.GetValue(1);
SqlCeResultSet scrsP = cmdP.ExecuteResultSet(ResultSetOptions.Scrollable);
result += "\t" + "<Pozitii>" + "\r\n\t";
while (scrsP.Read())
{
result = String.Empty;
result += "\t" + scrsP.GetValue(0) + "\r\n\t";
}
result += "</Pozitii>" + "\r\n";
result += "</Aparat>" + "\r\n";
sw.Write(result);
}
result = "</Aparate>" + "\r\n";
sw.Write(result);
sw.Close();
error at the line : SqlCeResultSet scrsP = cmdP.ExecuteResultSet(ResultSetOptions.Scrollable);
what could it be?
-
Jun 5th, 2007, 11:43 AM
#2
Re: Cannot generate an updatable cursor for the query because there is no updatable colu
Seeing as you are not updating the data, it would be best to use a data reader rather than a resultset.
I've updated your code a little - there's no need to use the "result" string - just dump what you need directly into the stream. The code's not tested nor compiled - don't have SQL CE.
Code:
const string PRODAPARAT =
"SELECT '<Pozitie Id=\"' + CONVERT(nvarchar,id) + '\" id_aparat=\"' + CONVERT(nvarchar,id_aparat) + '\" ContorInitial=\"' + ContorInitial + '\" ContorFinal=\"' +ContorFinal + '\" Produs=\"' + Produs +'\"/>' FROM Prodaparat WHERE Prodaparat.id_aparat={0}";
StreamWriter sw = File.CreateText(@"\Program Files\ContorPDA\Aparate.xml");
sw.Write("<?xml version='1.0'?>");
sw.Write(Environment.NewLine);
sw.Write("<Aparate>");
sw.Write(Environment.NewLine);
using(SqlCeCommand cmd = Biblio.pCon.CreateCommand());
{
using (SqlCeCommand cmdP = Biblio.pCon.CreateCommand());
{
cmd.CommandText = "SELECT '<Aparat Id=\"'+ CONVERT(nvarchar,id) + '\" Denumire=\"' + Denumire + " +
" '\" NumarCitire=\"' + NumarCitire + " +
" '\" DataCitire=\"' + CONVERT(nvarchar,DataCitire) + " +
" '\" ContorGeneralInitial=\"' + ContorGeneralInitial + " +
" '\" ContorGeneralFinal=\"' + ContorGeneralFinal +'\" Partener=\"' + Partener + '\" >', Aparat.id" +
" FROM Aparat";
using (SqlCeDataReader scrs = cmd.ExecuteReader());
{
while (scrs.Read())
{
string id = scrs.GetValue(0) + Environment.NewLine;
sw.Write(id);
cmdP.CommandText = string.Format(PRODAPARAT, scrs.GetValue(1));
sw.Write("\t<Pozitii>");
sw.Write(Environment.NewLine);
using (SqlCeDataReader scrsP = cmdP.ExecuteReader());
{
while (scrsP.Read())
{
sw.Write("\t{0}{1}\t",
scrsP.GetValue(0),
Environment.NewLine);
}
scrsP.Close();
}
sw.Write("</Pozitii>");
sw.Write(Environment.NewLine);
sw.Write("</Aparat>");
sw.Write(Environment.NewLine);
}
scrs.Close();
}
}
}
sw.Write("</Aparate>");
sw.Write(Environment.NewLine);
sw.Flush();
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|