逻辑问题再次出现

编程入门 行业动态 更新时间:2024-10-10 19:19:52
本文介绍了逻辑问题再次出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

I develop the form in asp which have two database tables Student StudentId(int,not null) FullName(nvarchar(30),not null)) DOB(smalldatetime) StudentCertificates StudentCerificateId(int,not null,pk) StudentId(int,not null,pk) CertificateName(nvarchar(30)) CertificateDate(smalldatetime) Below is the code page.aspx <pre lang="xml"><div> <script language="javascript" type="text/javascript"> function validate() { if (document.getElementById("<%=TextBox1.ClientID %>").value == "") { alert("Student Id is Required"); document.getElementById("<%=TextBox1.ClientID%>").focus(); return focus(); } if (document.getElementById("<%=TextBox2.ClientID %>").value == "") { alert("FullName is Required"); document.getElementById("<%=TextBox2.ClientID%>").focus(); return focus(); } if (document.getElementById("<%=TextBox3.ClientID %>").value == "") { alert("DOB is Required"); document.getElementById("<%=TextBox3.ClientID%>").focus(); return focus(); } </script> <asp:Panel ID="Panel1" runat="server" style="position: relative; top: 35px; left: 353px; width: 425px;"> <asp:Label ID="Label1" runat="server" Text="SudentRegistration"></asp:Label> <br /> <br /> <asp:Label ID="Label2" runat="server" Text="StudentId" AssociatedControlID="TextBox1"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" height="19px" style="position: relative" ontextchanged="TextBox1_TextChanged"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Id is Required" ValidationGroup="Student Registration">*</asp:RequiredFieldValidator> <br /> <br /> <asp:Label ID="Label3" runat="server" AssociatedControlID="TextBox2" Text="FullName"></asp:Label> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="Name is Required" ValidationGroup="Student Registration">*</asp:RequiredFieldValidator> <br /> <br /> <asp:Label ID="Label4" runat="server" AssociatedControlID="TextBox3" Text="DOB"></asp:Label> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3" ErrorMessage="DOB is Required" ValidationGroup="Student Registration">*</asp:RequiredFieldValidator> <br /> <br /> <asp:Button ID="Button1" runat="server" Text="Insert" ValidationGroup="Student Registration" onclick="Button1_Click" /> <br /> </asp:Panel> </div> <asp:Panel ID="Panel2" runat="server" style="position: relative; top: 59px; left: 354px; width: 425px; height: 297px"> <asp:Label ID="Label10" runat="server" Text="Student Certificates"></asp:Label> <br /> <br /> <asp:Label ID="Label6" runat="server" Text="StudentId" AssociatedControlID="TextBox4"></asp:Label> <asp:TextBox ID="TextBox4" runat="server" height="19px" ontextchanged="TextBox1_TextChanged" style="position: relative"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox4" ErrorMessage="Id is Required" ValidationGroup="Student Certificates">*</asp:RequiredFieldValidator> <br /> <br /> <asp:Label ID="Label7" runat="server" Text="CertificateId" AssociatedControlID="TextBox7"></asp:Label> <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="TextBox5" ErrorMessage="CertificateId is Required" ValidationGroup="Student Certificates">*</asp:RequiredFieldValidator> <br /> <br /> <asp:Label ID="Label5" runat="server" Text="CertificateName" AssociatedControlID="TextBox6"></asp:Label> <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="TextBox6" ErrorMessage="CertificateName is Required" ValidationGroup="Student Certificates">*</asp:RequiredFieldValidator> <br /> <br /> <asp:Label ID="Label8" runat="server" Text="CertificateDate" AssociatedControlID="TextBox7"></asp:Label> <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="TextBox7" ErrorMessage="CetificateDate is Required" ValidationGroup="Student Certificates">*</asp:RequiredFieldValidator> <br /> <br /> <br /> <asp:Button ID="Button4" runat="server" ValidationGroup="Student Certificates" Text="Insert" onclick="Button4_Click" /> <br /> <br /> <br /> <br /> </asp:Panel> <br /> <br /> <br /> <asp:ValidationSummary ID="ValidationSummary1" ValidationGroup="Student Registration" runat="server" /> <asp:ValidationSummary ID="ValidationSummary2" ValidationGroup="Student Certificates" runat="server" /> page.cs <pre lang="CS"> protected void Button1_Click(object sender, EventArgs e) { DateTime mydate; mydate = Convert.ToDateTime(TextBox3.Text); SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\omar\Documents\Visual Studio 2010\WebSites\PreInterviewPracticalAssignment\App_Data\Database.mdf;Integrated Security=True;User Instance=True"); con.Open(); string que = "insert into Student(StudentId,FullName,DOB) values(@StudentId,@FullName,@DOB)"; SqlCommand com = new SqlCommand(que, con); com.Parameters.Add("@StudentId",System.Data.SqlDbType.Int); com.Parameters.Add("@FullName", System.Data.SqlDbType.NVarChar); com.Parameters.Add("@DOB", System.Data.SqlDbType.SmallDateTime); com.Parameters["@StudentId"].Value = TextBox1.Text; com.Parameters["@FullName"].Value = TextBox2.Text; com.Parameters["@DOB"].Value = TextBox3.Text; com.ExecuteNonQuery(); con.Close(); } protected void Button4_Click(object sender, EventArgs e) { DateTime mydate; mydate = Convert.ToDateTime(TextBox7.Text); SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\omar\Documents\Visual Studio 2010\WebSites\PreInterviewPracticalAssignment\App_Data\Database.mdf;Integrated Security=True;User Instance=True"); con.Open(); string que1 = "insert into StudentCertificates(StudentId,StudentCertificateId,CertificateName,CertificateDate)values(@StudentId,@StudentCertificateId,@CertificateName,@CertificateDate)"; SqlCommand com = new SqlCommand(que1,con); com.Parameters.Add("@StudentId", System.Data.SqlDbType.Int); com.Parameters.Add("@StudentCertificateId", System.Data.SqlDbType.Int); com.Parameters.Add("@CertificateName", System.Data.SqlDbType.NVarChar); com.Parameters.Add("@CertificateDate", System.Data.SqlDbType.SmallDateTime); com.Parameters["@StudentId"].Value = TextBox4.Text; com.Parameters["@StudentCertificateId"].Value = TextBox5.Text; com.Parameters["@CertificateName"].Value = TextBox6.Text; com.Parameters["@CertificateDate"].Value = TextBox7.Text; com.ExecuteNonQuery(); con.Close(); }

MY PROBLEM IS THAT HOW I APPLY CONDITION?

MY PROBLEM IS THAT HOW I APPLY CONDITION?

limit the records entry to maximum of 5 records.

推荐答案

The question is so simple, there was no need to show a whole book of code. Just do this before the INSERT in your Stored Procedure. The question is so simple, there was no need to show a whole book of code. Just do this before the INSERT in your Stored Procedure. DECLARE @StudentId = 10 DECLARE @CertCount int SELECT @CertCount = COUNT(*) FROM StudentCertificates WHERE StudentID = @StudentID IF (@StudentId >=5) BEGIN RAISERROR('Only 5 certificates allowed per student', 1, 1); END

更多推荐

逻辑问题再次出现

本文发布于:2023-10-27 23:48:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534884.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:逻辑

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!