强类型DataSet的问题

时间:2016-03-31 15:36:51

标签: c# database visual-studio dataset

我在C#中创建一个TimeClock,用户在其中创建用户名和密码,然后将信息保存到数据库中。好吧,每当我引用DataSet时,我都会收到错误:“非静态字段,方法或属性需要对象引用'TimeClockProject.loginsDataSet.Logins.Get'”

以下是代码:

   using System;
   using System.Collections.Generic;
   using System.ComponentModel;
   using System.Data;
   using System.Drawing;
   using System.Linq;
   using System.Text;
   using System.Threading.Tasks;
   using System.Windows.Forms;
   using System.Security.Cryptography;
   using System.Data.Sql;
   using System.Data.SqlClient;


   namespace TimeClockProject
   {
       public partial class Form1 : Form
       {
           public Form1()
           {
               InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void AddUser(string username, string password, string confirmPass, string email)
    {
        //Loop through Logins Table
        foreach (DataRow row in loginsDataSet.Logins)
        {
            //And look for matching usernames
            if (row.ItemArray[0].Equals(username))
            {
                //If one is found, show message:
                MessageBox.Show("Username already exists");
                return;
            }
        }

        //Confirm pass must equal password.
        if (password != confirmPass)
        {
            MessageBox.Show("Passwords do not match");
        }
        //Password must be at least 8 characters long
        else if (password.Length < 8)
        {
            MessageBox.Show("Password must be at least 8 characters long");
        }

        //If there is no username
        else if (username == null)
        {
            MessageBox.Show("Must have Username");
        }
        //If all is well, create the new user!
        else
        {
            loginsDataSet.LoginsRow newUserRow = loginsDataSet.Logins.NewLoginsRow();

            string EncryptedPass = HashPass(password);
            newUserRow.Username = username;
            newUserRow.Password = EncryptedPass;

            loginsDataSet.Logins.Rows.Add(newUserRow);
            registerUserName.Text = String.Empty;
            registerPassword.Text = String.Empty;
            registerConfirmPassword.Text = String.Empty;
            MessageBox.Show("Thank you for Registering!");
        }
    }

    public string HashPass(string password)
    {
        SHA256 sha = new SHA256CryptoServiceProvider();

        //compute hash from the bytes of text
        sha.ComputeHash(ASCIIEncoding.ASCII.GetBytes(password));

        //get hash result after compute it
        byte[] result = sha.Hash;

        StringBuilder strBuilder = new StringBuilder();
        for (int i = 0; i < result.Length; i++)
        {
            //change it into 2 hexadecimal digits
            //for each byte
            strBuilder.Append(result[i].ToString("x2"));
        }

        return strBuilder.ToString();
    }

    private void registerButton_Click(object sender, EventArgs e)
    {
        AddUser(registerUserName.Text, registerPassword.Text, registerConfirmPassword.Text, registerEmail.Text);
    }

}
}

1 个答案:

答案 0 :(得分:0)

修复了问题,取消了输入的数据集