Checking if a datatable is null

后端 未结 7 1746
南旧
南旧 2021-02-19 22:02

The following code is what I\'ve been using to retrieve user information from a sql database.

            string userName = LoginUser.UserName;
            strin         


        
7条回答
  •  终归单人心
    2021-02-19 22:16

    You will get an empty DataTable if no records match, so you can check on the number of records returned:

    if (dt.Rows.Count > 0)
    

    And, slightly off topic, please read the comments below your question, then Google the terms SQL Injection and Parameterized SQL statements. Try starting with this.

提交回复
热议问题