我有一个查询,它应返回TRUE或FALSE.
var query = from c in db.Emp
from d in db.EmpDetails
where c.ID == d.ID && c.FirstName == "A" && c.LastName == "D"
// It should return TRUE when this above statement matches all these conditions
Run Code Online (Sandbox Code Playgroud)
我想将此查询结果附加到属性(字符串数据类型)
this.result = Conert.ToBoolean(query);
Run Code Online (Sandbox Code Playgroud)
如何在LINQ中实现这一点?
编辑:
EmpMapper类
public class EmpMapper
{
EmpEntities db;
// ID column already exists in the DB
private int ID;
// I am creating this property to add it from the UI side, depending on the certain conditions in …Run Code Online (Sandbox Code Playgroud) 我想在绑定到数据库的WPF数据网格中设置用户定义的列标题.
用于显示ServerID,EventlogID我想在列标题中显示为Server,Event Log.
我已经尝试过这些......
<DataGrid x:Name="dataGrid1" ItemsSource="{Binding}" AutoGenerateColumns="True" >
<DataGrid.Columns>
<DataGridTextColumn Header="Server" Width="Auto" IsReadOnly="True" Binding="{Binding Path=ServerID}" />
<DataGridTextColumn Header="Event Log" Width="Auto" IsReadOnly="True" Binding="{Binding Path=EventLogID}" />
</DataGrid.Columns>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)
这样可以正常工作,它会更改列标题,并且还会显示数据.
但我的问题是它显示两次作为XAML的前两个列标题和DB的其他两个列标题.
|Server|Event Log|ServerID|EventLogID|
Run Code Online (Sandbox Code Playgroud)
如何克服这种复制?请帮忙!
我有像这样的矩阵类数据网格.

这个网格完全是用XAML设计的
现在如何使用二维数组将值插入到这些datagridcell中?需要插入的值必须是bool数据类型(TRUE或FALSE).有任何想法吗 ?
我有一个从数据库显示的表.我想显示水平标题栏 - >垂直
我的表结构是
Server|Role|Status|Date
Run Code Online (Sandbox Code Playgroud)
但我想显示为
Server
Role
Status
Date
Run Code Online (Sandbox Code Playgroud)
我试图翻转数据集,并尝试构建它.最初构建成功但我无法在我的数据网格上查看任何数据.亲切的帮助,有没有其他方法来解决这个问题?
这是我的代码片段
SqlConnection con;
SqlDataAdapter da = null;
DataSet ds = null;
private void Page_Loaded(object sender, RoutedEventArgs e)
{
try
{
da = new SqlDataAdapter("Select * from [ServerDB_Test].[dbo].[ServerStatus] ", con);
ds = new DataSet();
foreach (DataTable dt in my_DataSet.Tables)
{
DataTable table = new DataTable();
for (int i = 0; i <= dt.Rows.Count; i++)
{
table.Columns.Add(Convert.ToString(i)); }
DataRow r;
for (int k = 0; k < dt.Columns.Count; k++)
{
r …Run Code Online (Sandbox Code Playgroud) 我有一个datagrid,显示一个绑定到SQL Server DB的表.我想每隔60秒设置一个Timer,检查任何更新,然后显示最新的更新数据.
到目前为止,我已经为datagrid创建了一个event_handler,它包含了对象调度程序计时器
private void dataGrid1_loaded(object sender, RoutedEventArgs e)
{
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 60);
dispatcherTimer.Start();
}
Run Code Online (Sandbox Code Playgroud)
现在我不知道如何继续使用事件处理程序来处理数据库中新更新的数据.
dispatcherTimer_Tick
Run Code Online (Sandbox Code Playgroud)
这是我用于填充数据网格的select语句.
private void Page_Loaded(object sender, RoutedEventArgs e)
{
try
{
String selectstatement = "select top 2 ItemID, ItemName,ConsumerName, Street, DOJ from ConsumarTB order by ItemID ";
da = new SqlDataAdapter(selectstatement, con);
ds = new DataSet();
da.Fill(ds);
dataGrid1.ItemsSource = ds.Tables[0].DefaultView;
}
catch (SqlException e)
{
Console.WriteLine(e.Message);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将WPF的DataGrid绑定到MS SQL数据库中的表.
1)首先,我创建了一个App.config文件,如下所示
<connectionStrings>
<add name="ConString" connectionString="Data Source=MYDataSB\SQLExpress;
User Id=sa;Password=gm03C3; Initial Catalog=MYDB;">
<connectionStrings/>
Run Code Online (Sandbox Code Playgroud)
2)其次,我在我的Form中添加了一个名为grdEventLog的数据网格
<Grid>
<DataGrid Name="grdEventLog"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
3)然后我将此代码添加到MainWindow.xaml.cs文件中,如下所示:
using System.Data;
using System.Data.SqlClient;
using System.Web;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
FillDataGrid();
}
private void FillDataGrid()
{
string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
string CmdString = string.Empty;
using (SqlConnection con = new SqlConnection(ConString))
{
CmdString = "SELECT Server,Date,Typ,Msg FROM EventLog";
SqlCommand cmd = new SqlCommand(CmdString, con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable("EventLog");
sda.Fill(dt); …Run Code Online (Sandbox Code Playgroud) 我创建了一个数据网格,它显示了一个从数据库填充的记录表,并希望在满足某些条件时为数据网格的单元格设置动画.为此,我创建了一个名为BlinkConverter的转换器类,它继承了IValueConverter.
为了使这个转换器付诸行动,我将项目命名空间映射到xaml编辑器上
xmlns:local="clr-namespace:BlinkApplication"
Run Code Online (Sandbox Code Playgroud)
注意: BlinkApplication是我的项目的名称
添加之后,我试图用Windows.Resources集合为Binding 创建一个BlinkConvertor类的实例
<Window.Resources>
<local:BlinkConverter x:key="Blink"></local:BlinkConverter>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
在我键入"local:"后,我的Intellisense没有检测到BlinkCoverter类,即使我尝试输入,我也有一个错误,指出"找不到本地类型:BlinkConverter.验证您是否缺少程序集引用,并且所有参考组件已经建成."
即使我已经在我的xaml编辑器中的xmlns下添加了整个项目.这有什么不对?我错过了任何参考?
我是否必须将Converter类添加为MainWindow.xaml.cs类的一部分,或者添加一个新的类命名Converter,然后将其映射到MainWindow.xaml.cs类?
因为在第一次尝试时,我在第一次尝试时添加了作为Mainwindow.xaml.cs的一部分,然后我的Intellisense没有检测到,但是当我添加一个单独的类作为Converter.cs时,我的Intellisense检测到但我不知道映射到Mainwindow.xaml.cs类的方法:(
Converter.cs
public class Converter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string cellvalue = value.ToString();
return cellvalue = ("Pass");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return false;
}
Run Code Online (Sandbox Code Playgroud)
MainWindow.xaml.cs
namespace BlinkApplication
{
public partial class MainWindow : Window
{
SqlConnection cn;
SqlDataAdapter da;
DataSet ds;
public …Run Code Online (Sandbox Code Playgroud) 我的UI上显示了两个数据网格.当我在datagrid 1上选择一个特定的行时,我想在datagrid 2上显示datagrid 1的详细信息.我正在从数据库中填充datagrid数据.这是两个数据库表结构.
注意:表都由数据库中的personid映射


这是迄今为止我尝试过的代码
Baseclass.cs
public class Baseclass
{
public event PropertyChangedEventHandler PropertyChanged;
protected void SetProperty<T>(ref T member, T value, [CallerMemberName] string propertyName = null)
{
member = value;
this.RaiseNotification(propertyName);
}
protected void RaiseNotification(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Run Code Online (Sandbox Code Playgroud)
person.cs
public class person : Baseclass
{
private int personID;
public int PersonID
{
get { return personID; }
set { this.SetProperty<int>(ref this.personID, value); }
}
private string firstName;
public string …Run Code Online (Sandbox Code Playgroud) 我试图从我的主表中删除记录,同时运行我理解的脚本,我的主表中的 Id 在其他 8 个表中被引用为外键。我不想使用 CASCADE DELETE,因为我必须更改表约束。我的主表称为 Job,其主键是“Id”,在其他表中被引用为外键“JobId”。
如何在从主作业表中删除之前删除相关表中的外键引用记录。
这是我的下面的代码。注释的代码只是一个预测。
SELECT * FROM [JOB] j WHERE Name=@Name AND Title=@Title AND Zip=@Zip
AND Id<>@Id AND NOT EXISTS (SELECT * FROM NewJob nj WHERE J.Id=nj.Id)
--DELETE FROM [Table1] a WHERE a.JobId = j.Id AND
--DELETE FROM [Table2] F WHERE f.JobId = j.Id AND
--DELETE FROM [Table3] jct WHERE jct.JobId = j.Id AND
--DELETE FROM [Table4] jch WHERE jch.JobId = j.Id AND
--DELETE FROM [Table5] jedu WHERE jedu.JobId = j.Id AND
--DELETE FROM …Run Code Online (Sandbox Code Playgroud) 如何将两个不同表的所有列显示为ONE?
我在MovieDB中有两个表,电影和movie_actors.电影的ID是主键和id的movie_actor是外键和movies_actor.id被引用到movies.id
TABLE MOVIES
id/title/director/genre/year_of_release
TABLE MOVIE_ACTOR
id/title/actor/age
Run Code Online (Sandbox Code Playgroud)
我使用了Union,但它不起作用,因为union要求相同数量的属性.但这里第一个表有4列,第二个表只有3列.
我想在一张表中显示
id/title/director/genre/year_of_release/actor/age
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我正在使用带有标签的WPF饼图,使用Zag studio中的文章 .此图表每1分钟刷新一次新值.它工作正常,但为什么每次刷新时饼图的颜色都会改变?是否有任何可能的方法来设置默认颜色.我显示的饼图只有两个切片.
我试过的,
<customControls:LabeledPieChart>
<customControls:LabeledPieChart.Palette>
<dv:ResourceDictionaryCollection>
<ResourceDictionary>
<Style TargetType="dvc:PieDataPoint">
<Setter Property="Background" Value="Green"/>
</Style>
<Style TargetType="dvc:PieDataPoint">
<Setter Property="Background" Value="Purple"/>
</Style>
</ResourceDictionary>
</dv:ResourceDictionaryCollection>
</customControls:LabeledPieChart.Palette>
</customControls:LabeledPieChart>
Run Code Online (Sandbox Code Playgroud)
上面的代码片段返回异常
'set property'System.Windows.ResourceDictionary.DeferrableContent'引发了异常.
任何身体可以帮忙?谢谢.
我正在尝试创建一个称为FileTypes的简单表。
我尝试了以下方法:
create table TestDB.dbo.FileTypes(
Date datetime not null,
File varchar(100) not null,
Type varchar(20) not null )
Run Code Online (Sandbox Code Playgroud)
但是我得到一个错误说明:
Incorrect Syntax near 'File' &
Incorrect Syntax near varchar(100) and varchar(20).Expecting SELECT, or '('
Run Code Online (Sandbox Code Playgroud)
这是关于什么的?请帮助..谢谢
c# ×9
wpf ×8
wpfdatagrid ×6
wpf-controls ×5
sql-server ×4
xaml ×4
sql ×2
asp.net ×1
datagrid ×1
join ×1
linq ×1
linq-to-sql ×1
wpftoolkit ×1