Hi!
I've a big problem by using the following query :
Code Snippet
public SqlCeResultSet selectRSQuery(String query)
{
SqlCeResultSet resultSet = initializeCommand(query).ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);
return resultSet;
}
SqlCeResultSet resultSet = sgb.selectRSQuery(
"SELECT p.pId, p.pLogin FROM Profiles p, ProfilesGroups pg, Groups g " +
"WHERE g.gId = pg.tpGroupId " +
"AND p.pId = pg.tpProfileId " +
"AND g.gProfileID = '" + app.Settings.Default.id + "'");
It return me this error :
Cannot generate an updatable cursor for the query because there is a non-standard join expression.
What can I do?
Thxx
Try using ANSI joins?
public SqlCeResultSet selectRSQuery(String query)
{
SqlCeResultSet resultSet = initializeCommand(query).ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);
return resultSet;
}
SqlCeResultSet resultSet = sgb.selectRSQuery(
"SELECT p.pId, p.pLogin
FROM Profiles p
inner join ProfilesGroups pg on pg.tpProfileID = p.pld
inner join Groups g on g.gld = pg.tpProfileId" +
"WHERE g.gProfileID = '" + app.Settings.Default.id + "'");
|||hello!
I tried it... and it returns me :
Cannot generate an updatable cursor for the query because there is no updatable column.
thx for help
|||re
if I remove the Options of the resultset.... It works..... but then It says me :
This operation is not valid because the cursor is not scrollable.
when I bind the resultset to my ListView :
lstViewTest.DataContext = resultSet;
edit : Here is the explanation of the problem :
Forward-only/Read-only Cursors
Forward-only/read-only cursors, referred to as forward-only cursors in earlier versions of SQL Server Compact Edition, are the fastest cursors, but cannot be updated.
The following is an example of how to obtain a forward-only/read-only cursor by using ADO.NET:
cmd.CommandText = "Select * from tablename";
SqlCeResultSet rs = cmd.ExecuteResultSet(ResultSetOptions.None);
Note You cannot create read-only cursors on query that returns only read only columns because internally all SQL Server Compact Edition cursors are updatable. SQL Server Compact Edition cannot update read-only columns returned in the SqlCeResultSet. Therefore, it would fail with the error "Cannot generate an updatable cursor for the query because there is no updatable column."
|||how can I fill my ListView without using a ResultSet ?
thx...
|||ExecuteReader returns a DataReader that can be fed to the DataTable.Load. Either that or create a DataAdapter and use the Fill method to create a DataTable. Bind the DataTable to the list.|||Hi!
I decided to use ObservableCollection! I load my objects with a sqlcedatareader in a ObservableCollection, and then bind it in xaml mode!
The disadvantage of this method is that I lost "the design preview" in Blend
Here is my code :
Code Snippet
public class ProfileI : INotifyPropertyChanged
{
private String _id;
private String _profileInfoID;
private String _login;
private String _password;
public ProfileI() { }
public ProfileI(string id, string profileInfoID, string login)
{
Id = id;
ProfileInfoID = profileInfoID;
Login = login;
}
public ProfileI(string id, string profileInfoID, string login, string password)
{
Id = id;
ProfileInfoID = profileInfoID;
Login = login;
Password = password;
}
#region Properties Getters/Setters
public String Login
{
get
{
return _login;
}
set
{
if (value != "")
{
if (value.Length < 5)
{
throw new ArgumentException(app.Resources.errorLoginTooSmall);
}
_login = value;
OnPropertyChanged("Login");
}
}
}
public String Password
{
get
{
return _password;
}
set
{
if (value != "")
{
if (value.Length < 5)
{
throw new ArgumentException(app.Resources.errorLoginTooSmall);
}
_password = value;
OnPropertyChanged("Password");
}
}
}
public string ProfileInfoID
{
get
{
return _profileInfoID;
}
set
{
_profileInfoID = value;
OnPropertyChanged("ProfileInfoID");
}
}
public string Id
{
get
{
return _id;
}
set
{
_id = value;
OnPropertyChanged("Id");
}
}
#endregion
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(String propertyName)
{
if (this.PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public class myProfilesI :
ObservableCollection<ProfileI>
{
public myProfilesI()
{
// On r?cup?re les "profiles-amis" de l'utilisateur
SingleDatabase sd = SingleDatabase.getInstance();
SqlCeDataReader sdr = sd.selectDRQuery(
"SELECT p.pId, p.pProfileInfoID, p.pLogin FROM Profiles p, ProfilesGroups pg, Groups g " +
"WHERE g.gId = pg.tpGroupId " +
"AND p.pId = pg.tpProfileId " +
"AND g.gProfileID = '" + app.Settings.Default.id + "'");
while (sdr.Read())
{
Add(new ProfileI(sdr["pId"].ToString(), sdr["pProfileInfoID"].ToString(), sdr["pLogin"].ToString()));
}
}
}
And my XAML file :
Code Snippet
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2006"
xmlns:ToDo="clr-namespace:ToDo"
x:Class="ToDo.ToDoConfig"
x:Name="Window"
Title="ToDoConfig"
Width="640" Height="480">
<Window.Resources>
<ObjectDataProvider x:Key="MyProfilesInfoDataSource"
ObjectType="{x:Type ToDo:myProfilesI}"/>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="0.169*"/>
<RowDefinition Height="0.831*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<ToDo:Footer HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Grid.Row="2"/>
<ToDo:Header HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Grid.RowSpan="1"/>
<ListView ItemsSource="{Binding Source={StaticResource MyProfilesInfoDataSource}}" IsSynchronizedWithCurrentItem="True" Grid.Row="1">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding=
"{Binding Path=Login}"
Header="Login" Width="100"/>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
Also note that it's not possible to use construtors like this :
Code Snippet
public ProfileI(string id, string profileInfoID, string login)
: this(id, profileInfoID, login, null)
{}
public ProfileI(string id, string profileInfoID, string login, string password)
{
Id = id;
ProfileInfoID = profileInfoID;
Login = login;
Password = password;
}
If you have a solution to conserve the design in Blend, I will be happy .
+++
No comments:
Post a Comment