我想匹配Account_No
表customers
中输入的[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");
}