我正在尝试确定产品表中是否存在产品.当我运行这个tsql时,它应该返回1并退出proc,因为产品表中不存在产品ID 7777,但是它返回0.如果我在没有if语句的情况下运行它并只执行select声明,它说的@prodID是null.我想知道为什么它不会进入if语句,因为我正在检查它是否为空值.在此先感谢您的帮助.
Declare @ProdID int
select @ProdID = dbo.productTbl.ProductID
from dbo.ProductTbl
inner join dbo.OrderTbl
on dbo.ProductTbl.ProductID = dbo.OrderTbl.ProductID
where dbo.OrderTbl.ProductID = 7777
if(@ProdID = null)
begin
raiserror('The product does not exist',16,1)
return 1
end
return 0
Run Code Online (Sandbox Code Playgroud) 我环顾四周,找不到这个问题的具体答案.我有两个数组,一个包含一个人列表,另一个包含一个带有name属性的Person对象.我试图遍历对象数组,如果人的.Name中的值等于字符串数组中的对应值,那么我将1添加到计数器.我已经看到了使用Linq给出的答案,但我对此并不熟悉.有没有一个基本的方法来做到这一点,我忽略或我需要使用Linq.提前致谢.这是我的代码.
int count = 0;
string[] names = new string[]{"John","Jim","Mary","Joan","Tim"};
ObservableCollection<Person> people = (ObservableCollection<Person>)Session["People"];
foreach (var pe in people)
{
for (int i = 0; i < names.Length; i++)
{
if (pe.Name == names[i])
count++;
}
}
Run Code Online (Sandbox Code Playgroud) 嗨,我正在尝试在包含学生 ID 和课程 ID 的链接器表中编辑学生成绩。我环顾四周,发现我需要将两个 id 参数引入视图中,而不仅仅是一个 id,然后更改操作链接以采用两个参数。但是当我点击索引中的编辑按钮时,我得到一个 404,说找不到页面。任何想法我哪里出错了?提前致谢。
这是我的索引视图
@model IEnumerable<S00132671CA2.Models.StudentCourse>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Grade)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Grade)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id= item.StudentId, CourseId = item.CourseId }) |
@Html.ActionLink("Details", "Details", new { id = item.StudentId, Course = item.CourseId }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table> …Run Code Online (Sandbox Code Playgroud) 我正在编写一个程序,使用可观察的集合将膳食类型过滤到不同的类别.我正在使用枚举对膳食进行分类,并且我有三个单独的方法使用相同的代码,在单击各自的按钮时将它们分成新的集合.三种枚举类型是素食,肉类和鱼类.我有两个可观察的收藏品,餐和过滤餐.我试图创建另一种方法,然后传递类别作为参数,但我无法让它工作!任何帮助将不胜感激.
private void btnVegetarian_Click(object sender, RoutedEventArgs e)
{
filteredMeals = new ObservableCollection<Meal>();
Meal newMeal = new Meal();
for (int i = 0; i < meals.Count; i++)
{
newMeal = meals[i];
if (newMeal.Category == MealCategory.Vegetarian)
{
filteredMeals.Add(newMeal);
}
}
lbxMeals.ItemsSource = filteredMeals;
}
private void btnMeat_Click(object sender, RoutedEventArgs e)
{
filteredMeals = new ObservableCollection<Meal>();
Meal newMeal = new Meal();
for (int i = 0; i < meals.Count; i++)
{
newMeal = meals[i];
if (newMeal.Category == MealCategory.Meat)
{
filteredMeals.Add(newMeal);
}
}
lbxMeals.ItemsSource …Run Code Online (Sandbox Code Playgroud)