0

新しいユーザーを登録するために使用している登録フォームがあります。ユーザー名 (電子メール) とパスワードを作成して mysql DB に挿入しても問題ありません。ただし、テキストボックスに挿入された値を Email という列の値と比較するにはどうすればよいでしょうか。

例 テキスト ボックス bee@gmail.com に電子メールを挿入し、mysql DB に接続する [次へ] ボタンをクリックします。値を比較したいのですが、Email: bee@gmail.com が DB テーブルに存在する場合は、ユーザーに知らせてください! これは可能ですか?

ありがとう

4

2 に答える 2

1

最初の一歩:

Create Procedure FindString(
@MyString nvarchar(50))
As
Begin
Select * From MyTable
Where Value = @MyString
End

クラスを作成します。

public class ReadData
{
    public bool FindString(string myString)
    {
        SqlConnection connection = new SqlConnection();
        connection.ConnectionString = "Server=..."; //Your connection string
        SqlCommand command = new SqlCommand();
        command.Connection = connection;
        command.CommandType = CommandType.StoredProcedure;
        command.CommandText = "FindString";
        command.Parameters.AddWithValue("@MyString", myString);
        try
        {
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                return true;
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        finally
        {
            if (connection.State == ConnectionState.Open)
                connection.Close();
        }                
        return false;
    }
}

クラスを使用します。例えば ​​:

ReadData r = new ReadData();

if (r.FindString("Shahingg"))
    MessageBox.Show("I Found it!");
else
    MessageBox.Show("I can't Find it!");
于 2013-01-14T19:51:25.487 に答える
0

私は答えを見つけました:

 Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button7.Click

    con = New MySqlConnection("Database=;" & _
                            "Data Source=;" & _
                            "User Id=;Password=;")


    con.Open()
    Try

        Query = "SELECT Email FROM users WHERE Email='bee@gmail.com'"

        cmd = New MySqlCommand(Query, con)

        reader = cmd.ExecuteReader()

        If reader.HasRows Then
            MessageBox.Show("Email taken")
            '  While reader.Read
            'MysqlData.Text = MysqlData.Text & reader.Item("Email")
            ' End While
        Else
            MessageBox.Show("Email does not exist")
        End If
    Catch ex As Exception


    End Try

End Sub
于 2013-01-14T20:30:42.623 に答える