难道我每一个学生的座位登记时间1。减去45? [英] Do I substract 1 from 45 each time a student registers for a seat?

查看:107
本文介绍了难道我每一个学生的座位登记时间1。减去45?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个不同的表2的字段名。

一个字段名被称为SeatCapacity。该字段名名称有45的值,它是在一个表中调用位置

再有就是叫上一个名为tblMain表RemainingSeats另一个字段。

tblMain表中包含注册的详细信息,如谁签约的登录ID,当然报名参加,培训等日期。

这RemainingSeats字段名应包含45就像SeatCapacity的初始值。

每当一个人注册了一个座位,1从RemainingSeats减去。

例如,如果RemainingSeats是45,我注册了一个座位,现在RemainingSeats应该只有44。

这推移,直到RemainingSeats是0在这种情况下,没有人能够再注册。

下面是我的问题,现在。

1,我怎么分配的45初始值RemainingSeats?

SeatCapacity应始终显示总席位待签约而RemainingSeats应该显示仅存的席位。

我试着在SSMS作为defaut增值45 tblMain设计模式,但我看不到这个值。

2,当我试图做像一个插入语句:

  s =INSERT INTO tblMain(CourseId,LocationId,dateId,RemainingSeats)VALUES
        S + =(与&的Request.QueryString(cosId)及与&​​amp;的Request.QueryString(LOCID)及与&​​amp;的Request.QueryString(iddate)及 (RemainingSeats-1))

我收到以下错误:

名为RemainingSeats是在此上下文中允许的。有效的前pressions是常数,不断前pressions,以及(在某些情况下)变量。列名是不允许的。

我如何解决这些问题?

感谢很多提前

下面code被认为能负荷训练细节,但现在它显示空白,因为没有纪录tblMain存在。

 的SelectCommand =选择l.LocationId,c.courseId,c.coursename,tm.trainingMode,t.availableSeats,d.dateid,d.trainingDates,d.trainingtime,C。 CourseDescription,i.instructorName,l.location,l.seating_capacity
                        从tblCourses C,tblMain T,tblTrainingDates D,tblLocations L,tblInstructors我,tblCourseInstructor IC,TM tblTrainingMode
                        其中,c.courseId = ic.CourseId和i.instructorId = ic.instructorId和l.locationid = c.locationid
                        和c.dateid = d.dateid和t.locationId = l.locationId和tm.trainingModeId = c.trainingModeId
              FilterEx pression =LocationId ='{0}'>
        < FilterParameters>


解决方案

如果你有,你养SeatCapacity的地方,那么你为什么不从那里复制它。

当我注意到你在tblMain创建行之前知道LocationID,并在位置表你有SeatCapacity,所以SQL查询将是:

...请使用参数插入的数据...

  INSERT INTO tblMain(CourceId,LocationId,dateId,RemainingSeats)
(SELECT @CourceID
,@LocationID
,@DateID
,SeatCapacity FROM WHERE的位置ID = @ LocationID);

在VB.NET加入PARAMATERS将是:

 昏暗的参数作为新System.Sql.SqlClient.SqlParameter(@ CourceID的Request.QueryString(cosId))

...等

然后参数添加到您的SqlCommand和执行查询

I have 2 fieldnames on 2 different tables.

One fieldname is called SeatCapacity. This fieldname name has a value of 45 and it is on a table called Locations

Then there is another field called RemainingSeats on a table called tblMain.

tblMain table contains details of registrations such as loginId of who signed up, course signed up for, date of training, etc.

This RemainingSeats fieldname should contain an initial value of 45 just like SeatCapacity.

Each time an individual signs up for a seat, 1 is substracted from RemainingSeats.

For instance, if RemainingSeats is 45 and I sign up for a seat, RemainingSeats now should only be 44.

This goes on till RemainingSeats is 0 in which case, no one can sign up anymore.

Here are my issues right now.

1, how do I assign initial value of 45 to RemainingSeats?

SeatCapacity should always show total seats to be signed up while RemainingSeats should show only remaining seats.

I tried adding 45 to tblMain in design mode in ssms as defaut value but I can't see this value.

2, When I tried doing an insert statement like:

 s = "INSERT INTO tblMain (CourseId, LocationId, dateId,RemainingSeats) VALUES "
        s += "(" & Request.QueryString("cosId") & ", " & Request.QueryString("locid") & ", " & Request.QueryString("iddate") & ",(RemainingSeats-1) )"

I get the following error:

The name "RemainingSeats" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.

How do I resolve these?

Thanks a lot in advance

The below code is supposed to load training details but right now it shows blank because no record exists in tblMain.

SelectCommand="select l.LocationId,c.courseId, c.coursename,tm.trainingMode,t.availableSeats,d.dateid,d.trainingDates, d.trainingtime, c.CourseDescription,i.instructorName, l.location,l.seating_capacity 
                        from tblCourses c,tblMain t,tblTrainingDates d, tblLocations l,tblInstructors i, tblCourseInstructor ic, tblTrainingMode tm
                        where c.courseId = ic.CourseId and i.instructorId = ic.instructorId and l.locationid = c.locationid
                        and c.dateid=d.dateid and t.locationId = l.locationId and tm.trainingModeId = c.trainingModeId" 
              FilterExpression="LocationId = '{0}'" >
        <FilterParameters>

解决方案

If you have a place where you keep a SeatCapacity, then why you not copying it from there.

As I noticed you know LocationID before creating row in tblMain, and in Location table you have a SeatCapacity, so SQL query will be:

...Please use parameters for inserted data...

INSERT INTO tblMain(CourceId, LocationId, dateId, RemainingSeats) 
(SELECT @CourceID
, @LocationID
, @DateID
, SeatCapacity FROM Locations WHERE ID=@LocationID);

in VB.NET adding paramaters will be:

Dim param AS New System.Sql.SqlClient.SqlParameter("@CourceID", Request.QueryString("cosId"))

... and so on

Then add parameters to your SqlCommand and execute query

这篇关于难道我每一个学生的座位登记时间1。减去45?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆