创建帐户以使用户能够注册 [英] creating account to enable users to be registered

查看:70
本文介绍了创建帐户以使用户能够注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是asp.net的初学者,我试图创建一个通过在sql数据库中注册用户的网页,而我得到此错误消息请帮助???

I am a beginner to asp.net and i was trying to crate a web page thta registers users in sql database and i got this error massage pls help???

Insert Error:Incorrect syntax near the keyword ''Full''.<br />
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.<br />
<br />
Exception Details: System.Exception: Insert Error:Incorrect syntax near the keyword ''Full''.<br />
<br />
Source Error:<br />
<br />
Line 66:             string msg = "Insert Error:";<br />
Line 67:             msg += ex.Message;<br />
Line 68:             throw new Exception(msg);<br />
Line 69:         }<br />
Line 70:         finally <br />





谢谢大家对我的帮助,这里是C#代码
这是改进的问题
我在〜\ Test \ trial.aspx页面中有两个名为name和lastname的文本框和一个提交按钮





thank u all for trying to help i am kind of new here.here is the C# code
here is the improved question
i have two text boxes named name and lastname and a submit button in an ~\Test\trial.aspx page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

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

    }
 private void ExecuteInsert(string name, string username) {
     SqlConnection conn = new SqlConnection();
     conn.ConnectionString = @"Data Source = .\sqlexpress;" +
                    "Database =Test ; Integrated Security=True";

     string sql = "INSERT INTO Test (name, username)";

        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlParameter[] param = new SqlParameter[7];
            //param[0] = new SqlParameter("@id", SqlDbType.Int, 20);
            // new SqlParameter("@ Full Name", param[0].SqlDbType.VarChar, 50);
            param[0] = new SqlParameter("@name", System.Data.SqlDbType.VarChar, 50);
            param[1] = new SqlParameter("@Uusername",System.Data.SqlDbType.VarChar,50);
            param[0].Value = username;
            param[1].Value = username;
            for (int i = 0; i < param.Length; i++)
            {
                cmd.Parameters.Add(param[i]);
                cmd.Parameters.Add("@name", System.Data.SqlDbType.VarChar).Value = txtfname;
                cmd.Parameters.Add("@Uusername", System.Data.SqlDbType.VarChar).Value = txtlname;
            }

            cmd.CommandType = System.Data.CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Insert Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
        finally
        {
            conn.Close();
        }
    }                                                                
 protected void  sub_Click(object sender, EventArgs e)
{
            //call the method to execute insert to the database
            ExecuteInsert(txtfname.Text, 
                          txtlname.Text);
            Response.Write("Record was successfully added!");
            ClearControls(Page);
        }
  public static void ClearControls(Control Parent){

        if (Parent is TextBox)
        { (Parent as TextBox).Text = string.Empty; }
        else
        {
            foreach (Control c in Parent.Controls)
                ClearControls(c);
        }
}      
}

推荐答案

有一个特殊字符
''

Full.您可以使用

STRING.Replace("''","''''")

或使用参数化查询.



谢谢
Ashish

or use parameterized query.



Thanks
Ashish


我认为您的sql查询字符串应该是这样的.

字符串sql ="INSERT INTO测试(名称,用户名)值(@ name,@ username);
I think ur sql query string should be like this.

string sql = "INSERT INTO Test (name, username) values (@name,@username);


这篇关于创建帐户以使用户能够注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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