-2

「;」で区切られたデータベースから複数の Student_names を入力するためのテキスト ボックスがあります。ボタンと一緒に。このボタンをクリックすると、各学生名をテキストボックスから分離し、入力された学生名が有効かどうか、またはデータベーステーブルに存在するかどうかを確認したい. 「「学生名」の学生は存在しません」という警告ボックス。複数の名前が有効でない場合、「studentname1,2,.. の学生は存在しません」と表示したいのですが、これはどのように可能ですか??

 String PageRefs =TextBox1.Text;

    if (PageRefs.Contains(";"))
    {
        String[] PageRefArray = PageRefs.Split(';');

        for (int f = 0; f < PageRefArray.Length; f++)
        {
           String name = PageRefArray[f];
  //Comparing the values from table to check name  exists in table.here for example the default name is set to "Niya"
            if (name  != "niya")
             {
                 ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('studentID '"+name +'" doesnt exists')", true);
                return;
         }
        } 

アラート ボックスに存在しない学生名のリストを表示するにはどうすればよいですか?

4

1 に答える 1

1

問題が正確に何であるかはわかりませんが、私が収集したものから、無効なユーザーをリストするエラーが生成されているので、次のようなものはどうですか:

// get the users from the textbox 
string[] users = input.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

// check if the user doesn't exist in the database and add him to a list of invalid users
List<string> invalidUsers = users.Where(user => !UserExists(user)).ToList();

// generate an error message
string errorMessage = string.Format("Students with the usernames: {0} don't exists",
                                    string.Join(", ", invalidUsers));

もちろん、これにより次のものが生成されます。

ユーザー名が test、123123 の学生は存在しません

于 2013-09-10T06:34:47.613 に答える