不搜索新数据 [英] not searching new data

查看:43
本文介绍了不搜索新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过使用此代码从数据库中搜索。这个数据是从execl sheet导入的。我也使用一些和它的工作添加新数据但是在这段代码中它只搜索从execl表导入的数据而不是新的数据......

但是代码是一样的,但是找不到问题请帮帮我















I am saerching from database by using this code.This data is import from execl sheet.I am also adding new data using some and its working but in this code it only search the data that was imported from execl sheet not the new data...
but the code is same cant figre out the problem please help me with that







protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection con;
            con = new SqlConnection(connstring);
            con.Open();



            //string str = "SELECT * FROM ['ISB VAS Nodes$']";
            if (DropDownList1.Text == "Type")
            {
                string str = "SELECT * FROM ['ISB VAS Nodes$'] where Type='" + TextBox2.Text + "'";
                //city is the column name in table
                SqlCommand cmd;
                cmd = new SqlCommand(str, con);
                SqlDataReader dr;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {


                    //if city is in 0 index of table
                    GridView1.DataSource = dr;
                    GridView1.DataBind();
                }
                else
                {
                    Response.Write("Value does not exist");

                }
                dr.Close();
                con.Close();
            }
             else if(DropDownList1.Text=="Desc") 
                {
                    string str = "SELECT * FROM ['ISB VAS Nodes$'] where [Desc]='" + TextBox2.Text + "'";
                    //city is the column name in table
                    SqlCommand cmd;
                    cmd = new SqlCommand(str, con);
                    SqlDataReader dr;
                    dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {


                        //if city is in 0 index of table
                        GridView1.DataSource = dr;
                        GridView1.DataBind();
                    }
                    else
                    {
                        Response.Write("Value does not exist");

                    }
                    dr.Close();
                    con.Close();
                }
            else if (DropDownList1.Text == "Model")
            {
                string str = "SELECT * FROM ['ISB VAS Nodes$'] where Model='" + TextBox2.Text + "'";
                //city is the column name in table
                SqlCommand cmd;
                cmd = new SqlCommand(str, con);
                SqlDataReader dr;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {


                    //if city is in 0 index of table
                    GridView1.DataSource = dr;
                    GridView1.DataBind();
                }
                else
                {
                    Response.Write("Value does not exist");

                }
                dr.Close();
                con.Close();
            }
            else if (DropDownList1.Text == "SN")
            {
                string str = "SELECT * FROM ['ISB VAS Nodes$'] where SN='" + TextBox2.Text + "'";
                //city is the column name in table
                SqlCommand cmd;
                cmd = new SqlCommand(str, con);
                SqlDataReader dr;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {


                    //if city is in 0 index of table
                    GridView1.DataSource = dr;
                    GridView1.DataBind();
                }
                else
                {
                    Response.Write("Value does not exist");         

                }
                dr.Close();
                con.Close();
            }
            else if (DropDownList1.Text == "Asset Tag")
            {
                string str = "SELECT * FROM ['ISB VAS Nodes$'] where AssetTag='" + TextBox2.Text + "'";
                //city is the column name in table
                SqlCommand cmd;
                cmd = new SqlCommand(str, con);
                SqlDataReader dr;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {


                    //if city is in 0 index of table
                    GridView1.DataSource = dr;
                    GridView1.DataBind();
                }
                else
                {
                    Response.Write("Value does not exist");

                }
                dr.Close();
                con.Close();
            }
            else if (DropDownList1.Text == "ID")
            {
                string str = "SELECT * FROM ['ISB VAS Nodes$'] where ID='" + TextBox2.Text + "'";
                //city is the column name in table
                SqlCommand cmd;
                cmd = new SqlCommand(str, con);
                SqlDataReader dr;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {


                    //if city is in 0 index of table
                    GridView1.DataSource = dr;
                    GridView1.DataBind();
                }
                else
                {
                    Response.Write("Value does not exist");

                }
                dr.Close();
                con.Close();
            }

推荐答案

'];
if (DropDownList1.Text == 输入
{
string str = SELECT * FROM [' ISB VAS节点
']"; if (DropDownList1.Text == "Type") { string str = "SELECT * FROM ['ISB VAS Nodes


']其中Type =' + TextBox2.Text + ';
// city是表格中的列名
SqlCommand cmd;
cmd = new SqlCommand(str,con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{


// 如果city在表的0索引中
GridView1.DataSource = dr;
GridView1.DataBind();
}
else
{
Response.Write( 值不存在);

}
dr.Close();
con.Close();
}
else if (DropDownList1.Text == Desc
{
string str = SELECT * FROM ['ISB VAS Nodes
'] where Type='" + TextBox2.Text + "'"; //city is the column name in table SqlCommand cmd; cmd = new SqlCommand(str, con); SqlDataReader dr; dr = cmd.ExecuteReader(); if (dr.Read()) { //if city is in 0 index of table GridView1.DataSource = dr; GridView1.DataBind(); } else { Response.Write("Value does not exist"); } dr.Close(); con.Close(); } else if(DropDownList1.Text=="Desc") { string str = "SELECT * FROM ['ISB VAS Nodes


']其中[Desc] =' + TextBox2.Text + ';
// city是表中的列名
SqlCommand cmd;
cmd = new SqlCommand(str,con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{


// 如果city在表的0索引中
GridView1.DataSource = dr;
GridView1.DataBind();
}
else
{
Response.Write( 值不存在);

}
dr.Close();
con.Close();
}
else if (DropDownList1.Text == 型号
{
string str = SELECT * FROM ['ISB VAS Nodes
'] where [Desc]='" + TextBox2.Text + "'"; //city is the column name in table SqlCommand cmd; cmd = new SqlCommand(str, con); SqlDataReader dr; dr = cmd.ExecuteReader(); if (dr.Read()) { //if city is in 0 index of table GridView1.DataSource = dr; GridView1.DataBind(); } else { Response.Write("Value does not exist"); } dr.Close(); con.Close(); } else if (DropDownList1.Text == "Model") { string str = "SELECT * FROM ['ISB VAS Nodes


这篇关于不搜索新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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