I rewrite my add to database code and now when I want to add data into database I have this error
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: String or binary data would be truncated.
The statement has been terminated.
And here you have my part of
if (Parola.Text != rparola.Text)
{
MessageBox.Show("Parolele nu se potrives!");
return;
}
string emailCheck = Email.Text;
bool valid = false;
int count_dot = 0;
for (int i = 0; i < emailCheck.Length; i++)
if (emailCheck[i] == '@') valid = true;
else if (emailCheck[i] == '.') count_dot++;
if (valid == false || count_dot == 0)
{
MessageBox.Show("Email invalid!");
return;
}
con = new SqlConnection(@"Data Source=MARIA-PC;Initial Catalog=Account;Integrated Security=True");
con.Open();
cmd = new SqlCommand("INSERT into [dbo].[Cont] (Nume_utilizator,Parola,Nume,Prenume,Data_nasterii,Email,Ocupatia) VALUES (@Nume_utilizator,@Parola,@Nume,@Prenume,@Data_nasterii,@Email,@Ocupatia)", con);
cmd.Parameters.Add("@Nume_utilizator", Nume_utilizator.Text);
cmd.Parameters.Add("@Parola", Parola.Text);
cmd.Parameters.Add("@Nume", Nume.Text);
cmd.Parameters.Add("@Prenume", Prenume.Text);
cmd.Parameters.Add("@Data_nasterii", DateTime.Parse(Data_nasterii.Text));
cmd.Parameters.Add("@Email", Email.Text);
cmd.Parameters.Add("@Ocupatia", Ocupatie.SelectedItem.ToString());
cmd.ExecuteNonQuery();
con.Close();
Whitout password checker (check if password and retype password are the same) and email checher (check if email have email structure) my application is working, but when I checked this two I received the error.
I search on the internet to fix it, but I can't and now I need your help to explain me what can I do to resolve my problem.
Here you have a photo with my table
What do you think I can do?