使用客户tabe Account_No验证Account_No

时间:2015-10-26 18:15:08

标签: c# sql asp.net sql-server-2008

我想匹配Account_Nocustomers中输入的[Cus_ID] ,[Name] ,[Email] ,[Account_No] FROM [NewImport_DB].[dbo].[Customer]客户。现在我有一个页面,我必须再次写入Account_No,现在,如果我再次输入一些无效的Account_No那么它必须给我一条消息You entered invalid Account_No。为此,我尝试了以下代码,但每次提示我You entered invalid Account_No。请看一下。谢谢。 首先我尝试了这段代码......

int d;
        if (Session["UserCheck"] != null)
        {
            //Retrieving CustomerID from Session
            d = Convert.ToInt32(Session["CustomerID"]);
            //  lblCusID.Text = "Cus_ID : " + d;
        }
        else
        {
            return;
        }

        // Getting Account_No from Customers and matching with enterd Account_No in txtAcntNo.Text
        SqlCommand cmd1 = new SqlCommand("select * FROM [NewImport_DB].[dbo].[Customer] where Account_No = '" + txtAcntNo.Text + "' ", con);
        //SqlCommand cmd1 = new SqlCommand("select Account_No FROM [NewImport_DB].[dbo].[Customer] where Cus_ID = '" + d + "' ", con);
        con.Open();
        var acc = cmd1.ExecuteScalar();
        con.Close();

        if (acc == txtAcntNo.Text)
        {
            con.Open();
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "INSERT INTO [NewImport_DB].[dbo].[Transfer_Pay]([User_ID] ,[Bank_Name], [Account_No] ,[Date]) VALUES ('" + d + "' ,'" + txtBnkame.Text + "', '" + txtAcntNo.Text + "', GETDATE())";
            cmd.ExecuteNonQuery();
            con.Close();
            Response.Redirect("/shipments.aspx");
        }
        else
        {
            Response.Write("<script>alert('You entere invalid Account_No!')</script>");
        }

在失败之后,我尝试了这个......

int d;
        if (Session["UserCheck"] != null)
        {
            //    //Retrieving UserName from Session
            d = Convert.ToInt32(Session["CustomerID"]);
            //  lblCusID.Text = "Cus_ID : " + d;
        }
        else
        {
            return;
        }

        if (txtBnkame.Text == "" || txtAcntNo.Text == "")
        {
            Response.Redirect("transfer_pay.aspx");
        }

        else
        {
            string a = "0";

            SqlCommand cmd = new SqlCommand("select * FROM [NewImport_DB].[dbo].[Customer] where Account_No = '" + txtAcntNo.Text + "' ", con);
            SqlDataReader r;
            con.Open();
            r = cmd.ExecuteReader();
            if (r.Read())
            {
                r.Close();
                con.Close();
            }
            else
            {
                r.Close();
                con.Close();
                //lblError.Text = "Invalid User Name or Password !";
                Response.Write("<script>alert('You entere invalid Account_No!')</script>");
            }
            con.Open();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "INSERT INTO [NewImport_DB].[dbo].[Transfer_Pay]([User_ID] ,[Bank_Name], [Account_No] ,[Date]) VALUES ('" + d + "' ,'" + txtBnkame.Text + "', '" + txtAcntNo.Text + "', GETDATE())";
            cmd.ExecuteNonQuery();
            con.Close();
            Response.Redirect("/shipments.aspx");
        }

以下是我正在输入Account_No的页面图片 page image

0 个答案:

没有答案