简体   繁体   中英

Asp.NET label displays

So i have this .Net website which is very basic and simple since i am creating it to learn .Net and pratice. For the moment i have a form that after some inputs checks in the database and ant displays data. What i what now to do but im not figuring out yet how to do it is that:

If the system checks and there is no data equal to the input in the database the label posts a msg like: "NO DATA FOUND" Here is the code i used for checking and displaying data after clickin submit button:

protected void Search_Click(object sender, EventArgs e)
    {
       try
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnect"].ConnectionString);
            con.Open();

            SqlCommand cnd = new SqlCommand();

            cnd.CommandText = "select * FROM [dbconnect] ";
            cnd.Connection = con;
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cnd;
            DataSet ds = new DataSet();
            da.Fill(ds, " dbconnect ");
            SqlCommandBuilder cb = new SqlCommandBuilder(da);
            DataRow drow = ds.Tables["dbconnect"].NewRow();

            drow["userName"] = TextBox3.Text;
            drow["rollno"] = TextBox4.Text;

            ds.Tables["TableName "].Rows.Add(drow);
            da.Update(ds, " dbconnect ");
        }

        catch(Exception EX)
        {
            string A = "";
        }

}

how can i make my label to post a msg if from the button i will not have a response

如果在网页上添加一个Label控件(称为lblMessage),那么在上面的代码结尾,您可以执行以下操作:

lblMessage.Text = "No results found";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM