请帮我填写我的报名表 [英] Please help me with my registration form

查看:92
本文介绍了请帮我填写我的报名表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我是ASP.NET的新手

我想为我的网站制作一个注册表,我不知道为什么会这样不工作当我输入用户的信息并点击提交时,它什么都不做。



这里是我的代码:

Hello there,
I'm a newbie to ASP.NET
I want to make a registration form for my website, and I don't know why it's not working. when I enter user's information and click submit, it does nothing.

here is my code:

 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;
using System.Data.SqlClient;

public partial class AdminUser : System.Web.UI.Page
{
    string StrConnect = ConfigurationManager.ConnectionStrings["WebUserDBConnectionString"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void button1_Click(object sender, EventArgs e)
    {
        string strPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text.Trim(), "md5");
        SqlConnection conn = new SqlConnection(StrConnect);
        try
        {
            conn.Open();
            string cmdText = "insert into Users values('"
                               + name.Text.Trim() + "','"
                               + strPwd + "','"
                               + TextBox3.Text.Trim() + "','"
                               + sex.SelectedItem.Text.Trim() + "','"
                               + Convert.ToDateTime(DropDownList1.SelectedItem.Text + "-" + DropDownList2.SelectedItem.Text + "-" + DropDownList3.SelectedItem.Text) + "','"
                               + TextBox4.Text + "','"
                               + DropDownList4.SelectedItem.Text + "','"
                               + TextBox5.Text + "',"
                               + "getdate()"
                               + ")"
                               ;
            SqlCommand comm = new SqlCommand(cmdText, conn);
            int nResult;
            nResult = comm.ExecuteNonQuery();
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('" + name.Text + ",Registration successful !!!" + "')</script>");
        }
        catch (SqlException ex)
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('" + ex.Message + "')</script>");
        }
        finally
        {
            conn.Close();
        }
    }
    protected void button2_Click(object sender, EventArgs e)
    {

    }
}

推荐答案

为了更好地理解

先试试 [ ^ ]

然后

试试这个 [ ^ ]
For better understanding
Try this first[^]
And then
try this[^]


string cmdText =插入用户值('

+ na me.Text.Trim()+','

+ strPwd +','

+ TextBox3.Text.Trim()+','

+ sex.SelectedItem.Text.Trim()+','

+ Convert.ToDateTime(DropDownList1.SelectedItem.Text + - + DropDownList2。 SelectedItem.Text + - + DropDownList3.SelectedItem.Text)+','

+ TextBox4.Text +','

+ DropDownList4.SelectedItem .Text +','

+ TextBox5.Text +',

+getdate()

+)

;







getdate()!!!我想你正在将String插入dateTime:D

你可以使用DateTime.Now而不是



试试这个







string cmdText =插入用户值('

+ name.Text.Trim ()+','

+ strPwd +','

+ TextBox3.Text.Trim()+','

+ sex.SelectedItem.Text.Trim()+','

+ Convert.ToDateTime(DropDownList1.SelectedItem.Text + - + DropDownList2.SelectedItem.Text + - + DropDownList3.SelectedItem.Text+','

+ TextBox4.Text +','

+ DropDownList4.SelectedItem.Text +' ,'

+ TextBox5.Text +',

+ DateTim e.Now

+)

;
string cmdText = "insert into Users values('"
+ name.Text.Trim() + "','"
+ strPwd + "','"
+ TextBox3.Text.Trim() + "','"
+ sex.SelectedItem.Text.Trim() + "','"
+ Convert.ToDateTime(DropDownList1.SelectedItem.Text + "-" + DropDownList2.SelectedItem.Text + "-" + DropDownList3.SelectedItem.Text) + "','"
+ TextBox4.Text + "','"
+ DropDownList4.SelectedItem.Text + "','"
+ TextBox5.Text + "',"
+ "getdate()"
+ ")"
;



getdate() !!! i think you are inserting String into dateTime :D
you can use DateTime.Now instead

try this



string cmdText = "insert into Users values('"
+ name.Text.Trim() + "','"
+ strPwd + "','"
+ TextBox3.Text.Trim() + "','"
+ sex.SelectedItem.Text.Trim() + "','"
+ Convert.ToDateTime(DropDownList1.SelectedItem.Text + "-" + DropDownList2.SelectedItem.Text + "-" + DropDownList3.SelectedItem.Text) + "','"
+ TextBox4.Text + "','"
+ DropDownList4.SelectedItem.Text + "','"
+ TextBox5.Text + "',"
+ DateTime.Now
+ ")"
;


这篇关于请帮我填写我的报名表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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