I have created a database in my VS 2013 and added it as a datasource. VS have generated a class for my database and a method insert
:
private void registrationButton_Click(object sender, EventArgs e)
{
var adapter = new LogPassDataSetTableAdapters.TableTableAdapter();
var table = new LogPassDataSet.TableDataTable();
var data = adapter.GetData();
MD5 md5 = new MD5CryptoServiceProvider();
Form1 form1 = new Form1();
var pass = passwordTextR.Text.ToString();
byte[] result = md5.ComputeHash(Encoding.UTF8.GetBytes(pass));
for (int i = 0; i <= data.Rows.Count; i++)
{
if (data.Rows.Count == 0)
{
adapter.Insert(logInTextR.Text.ToString(), BitConverter.ToString(result).Replace("-", string.Empty));
MessageBox.Show("Registration complete");
break;
}
else if (logInTextR.Text.ToString() == data[i].Login.ToString())
{
MessageBox.Show("This login already use");
break;
}
else if (i == data.Rows.Count)
{
adapter.Insert(logInTextR.Text.ToString(), BitConverter.ToString(result).Replace("-", string.Empty));
MessageBox.Show("Registration complete");
break;
}
}
this.Hide();
form1.Show();
}
This code doesn't fill the database. What is the problem? Can you help me with it?