想請教一下
如下的判斷,
我是想做如輸入相同值就跳重複值訊息,
有讀到資料就帶資料進來,如果沒有符合就跳找不到品號,
現在這樣是找到資料還是會跳重複值的訊息
protected void t_TextChanged(object sender, EventArgs e)
{
string ConnectionString=System.Web.Configuration.WebConfigurationManager.ConnectionStrings["readerConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
DataTable dt = (DataTable)ViewState["Curtbl"];
foreach (GridViewRow rw in this.gv.Rows)
{
TextBox tTextBox1 = (TextBox)rw.FindControl("TextBox1");
TextBox tTextBox2 = (TextBox)rw.FindControl("TextBox2");
TextBox tTextBox3 = (TextBox)rw.FindControl("TextBox3");
TextBox tTextBox4 = (TextBox)rw.FindControl("TextBox4");
string m_Text = tTextBox1.Text.Trim();
bool m_IsExist = false;
foreach (DataRow dr in dt.Rows)
{
if (m_Text == dr[1].ToString().Trim())
{
m_IsExist = true;
break;
}
}
if (!m_IsExist)
{
try
{
SqlCommand command = new SqlCommand("select MB001,MB002,MB003,MB064 from INVMB where MB001='" + tTextBox1.Text + "'", conn);
//conn.Open();
SqlDataReader reader1;
reader1 = command.ExecuteReader();
if (reader1.Read() && tTextBox1.Text != "")
{
tTextBox2.Text = reader1["MB002"].ToString();
tTextBox3.Text = reader1["MB003"].ToString();
string r_qty = reader1["MB064"].ToString();
double a = Convert.ToDouble(r_qty.ToString());
tTextBox4.Text = a.ToString();
}
else
{
String TransferPage;
TransferPage = "<script>alert('找不到該品號!')</script>";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "temp", TransferPage, false);
tTextBox1.Text="";
}
reader1.Close();
}
catch
{
}
}
else
{
//tTextBox1.Text = "";
String TransferPage1;
TransferPage1 = "<script>alert('重複值!')</script>";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "temp", TransferPage1, false);
//this.lblErrorMessage.Visible = true;
}
}
}