Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从SQL表中提取单个行值_C#_.net_Sql - Fatal编程技术网

C# 从SQL表中提取单个行值

C# 从SQL表中提取单个行值,c#,.net,sql,C#,.net,Sql,我有一个sql表,需要从中提取某些数据。例如: 这是我的sql表的一个例子,我需要为我的应用程序提取星期一的红色,以获得一个实时互动程序。如此类推,我可能需要抽周二的红色或黄色 是否有一个查询可以帮助我实现这一点 如果我没有弄错的话,这是一个基本的查询,可以满足您的需求。我假设表头是列名 获取周一的红色: select [monday] from table where [key] = 'Reds' select [tuesday] from table where [key] = 'Red

我有一个sql表,需要从中提取某些数据。例如:

这是我的sql表的一个例子,我需要为我的应用程序提取星期一的红色,以获得一个实时互动程序。如此类推,我可能需要抽周二的红色或黄色


是否有一个查询可以帮助我实现这一点

如果我没有弄错的话,这是一个基本的查询,可以满足您的需求。我假设表头是列名

获取周一的红色:

select [monday] from table where [key] = 'Reds'
select [tuesday] from table where [key] = 'Reds'
select Monday from SUMMARY where Key LIKE 'Reds' //Can also match wildcards, Slower
select Tuesday from SUMMARY where Key = 'Reds'  //Preferred , Faster 
获取周二的红色:

select [monday] from table where [key] = 'Reds'
select [tuesday] from table where [key] = 'Reds'
select Monday from SUMMARY where Key LIKE 'Reds' //Can also match wildcards, Slower
select Tuesday from SUMMARY where Key = 'Reds'  //Preferred , Faster 
对于周一的红色:

select [monday] from table where [key] = 'Reds'
select [tuesday] from table where [key] = 'Reds'
select Monday from SUMMARY where Key LIKE 'Reds' //Can also match wildcards, Slower
select Tuesday from SUMMARY where Key = 'Reds'  //Preferred , Faster 
对于周二的红军:

select [monday] from table where [key] = 'Reds'
select [tuesday] from table where [key] = 'Reds'
select Monday from SUMMARY where Key LIKE 'Reds' //Can also match wildcards, Slower
select Tuesday from SUMMARY where Key = 'Reds'  //Preferred , Faster 
*根据您的评论,假设SUMMARY是您的表名。
两种方法都有效
请参见此处的LIKE=之间的区别:
请在此处尝试:

我正在寻找sql代码谢谢您的回复。我尝试了这个查询,但发现了错误。我从摘要中写入SELECT[Monday],其中[Key]=“Reds”,并得到一个错误,表示表名附近有错误。不确定我做错了什么。您使用的是哪种DBMS?Microsoft SQL Server?这很有效。非常感谢。