填写注册表后数据未插入数据库表中 [英] Data is not getting insert in database table after filling registration form

查看:107
本文介绍了填写注册表后数据未插入数据库表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在填写完所有数据文件后,单击提交"按钮,什么都没有发生...只有密码文本框清楚了...它也没有显示任何错误...我不知道在哪里我的代码中的问题.

这是.aspx代码:

After filling all the datails in the registration form and click on submit button nothing is happening...only the password textbox get clear... also it is not showing any error... I don''t know where is the problem in my code.

Here is .aspx code:

<%@ Page Language="C#" MasterPageFile="~/MainMasterPage.master" AutoEventWireup="true"

    CodeFile="StudentRegistration.aspx.cs" Inherits="StudentRegistration" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentBody" runat="Server">
    <center>
        <form id="form1" runat="server">
        <table>
            <tr>
                <td colspan="2">
                    Registration Form
                </td>
            </tr>
            <tr>
                <td>
                    First Name
                </td>
                <td>
                    <asp:TextBox ID="txtFName" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvFName" runat="server" ControlToValidate="txtFName"

                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Last Name
                </td>
                <td>
                    <asp:TextBox ID="txtLName" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvLName" runat="server" ControlToValidate="txtLName"

                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Contact No
                </td>
                <td>
                    <asp:TextBox ID="txtContactNo" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvContactNo" runat="server" ControlToValidate="txtContactNo"

                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Email-Id
                </td>
                <td>
                    <asp:TextBox ID="txtEmail" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtContactNo"

                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Address
                </td>
                <td>
                    <asp:TextBox ID="txtAddress" runat="server" Width="150" TextMode="MultiLine"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvAddress" runat="server" ControlToValidate="txtAddress"

                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Date Of Birth
                </td>
                <td>
                    <asp:TextBox ID="txtDOB" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvDOB" runat="server" ControlToValidate="txtDOB"

                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    User Name
                </td>
                <td>
                    <asp:TextBox ID="txtUserName" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="efvUserName" runat="server" ControlToValidate="txtUserName"

                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Password
                </td>
                <td>
                    <asp:TextBox ID="txtPassword" runat="server" Width="150" TextMode="Password"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvpassword" runat="server" ControlToValidate="txtPassword"

                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Role
                </td>
                <td>
                <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem>Student</asp:ListItem>
                    <asp:ListItem>Teacher</asp:ListItem>
                </asp:RadioButtonList>
                
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Select role" ControlToValidate="RadioButtonList1"></asp:RequiredFieldValidator>
           </td>
                     </tr>
            <tr>
                <td>
                    Security Question
                </td>
                <td>
                    <asp:TextBox ID="txtSecQues" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvsecques" runat="server" ControlToValidate="txtSecQues"

                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Security Answer
                </td>
                <td>
                    <asp:TextBox ID="txtSecAns" runat="server" Width="150"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvSecAns" runat="server" ControlToValidate="txtSecAns"

                        ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
                </td>
            </tr>
        </table>
        <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
        </form>
    </center>
</asp:Content>



Code-behind



Code-behind

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class StudentRegistration : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    static int i;
    static string strMsg;
    BALQuestions insobj = new BALQuestions();
    public void InsertStudentDetails()
    {

        DateTime DateConverted;
        bool IsValid = DateTime.TryParse(txtDOB.Text.Trim(), out DateConverted);
        if (IsValid == false)
        {
            return; //value in TextBox2 is not valid
        }

        insobj.FName = txtFName.Text;
        insobj.LName = txtLName.Text;
        insobj.ContactNo = txtContactNo.Text;
        insobj.Email = txtEmail.Text;
        insobj.Address = txtAddress.Text;
        insobj.DOB = DateConverted.ToString("dd-MM-yyyy");
        insobj.UserName = txtUserName.Text;
        insobj.Password = txtPassword.Text;
        insobj.role = RadioButtonList1.SelectedValue;
        insobj.SecQues = txtSecQues.Text;
        insobj.SecAns = txtSecAns.Text;
        i = insobj.InsertStudent(out strMsg);
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            InsertStudentDetails();
            if (i &gt; 1)
            {
                ClearData();
                lblMsg.Text = strMsg;
            }
            else
                lblMsg.Text = strMsg;
            
        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
        }
    }
    public void ClearData()
    {
        txtFName.Text= txtLName.Text = txtContactNo.Text = txtAddress.Text= txtDOB.Text="";
        txtUserName.Text = txtPassword.Text = txtSecQues.Text = txtSecAns.Text = "";
    }
}

推荐答案

Start with the debugger.
Put a breakpoint on the first line of the InsertStudentDetails method, and run your code in the debugger. When it tries to execute the method, it will stop and let you take control. Step through each line one by one, looking closely at exactly what is happening.
At a guess, your DateTime.TryParse is failing - but you need to look closely at your data to find out why.
If it isn''t, then continue stepping until something happens that you don''t expect, or some data looks wrong.
We can''t do any of this for you - we don''t have access to your data, and couldn''t run your code under the same conditions if we did! So give it a try and see what you can find out.
Start with the debugger.
Put a breakpoint on the first line of the InsertStudentDetails method, and run your code in the debugger. When it tries to execute the method, it will stop and let you take control. Step through each line one by one, looking closely at exactly what is happening.
At a guess, your DateTime.TryParse is failing - but you need to look closely at your data to find out why.
If it isn''t, then continue stepping until something happens that you don''t expect, or some data looks wrong.
We can''t do any of this for you - we don''t have access to your data, and couldn''t run your code under the same conditions if we did! So give it a try and see what you can find out.


这篇关于填写注册表后数据未插入数据库表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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