F
F.oliveirarocha
Guest
Hi folks,
I need your help once again, I'm doing exactly the same code, to insert users, and to insert clients at the SQL Server,
However the method for insert users is working, and to insert clients is not working. I've tried everything and I can't figure out where is the error.
Please help me out you guys with your remarkable knowledge, What am I doing wrong?
Thanks once again for your help.
#region Methods of Insert.
private bool cadastrarUser(User users) // Insert Uers is working perfect
{
try
{
StringBuilder query = new StringBuilder();
query.AppendFormat("insert into Users(username, loginname, [password], [date], userlogged, datelogged)");
query.AppendFormat(" VALUES (@UserName, @loginname, @password, @Date, @userlogged, @datelogged)");
connectionOpen();
using (SqlCommand cmd = connection.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = query.ToString();
cmd.Parameters.Clear();
cmd.Parameters.Add(new SqlParameter("@UserName", users.username));
cmd.Parameters.Add(new SqlParameter("@loginname", users.loginname));
cmd.Parameters.Add(new SqlParameter("@password", users.password));
cmd.Parameters.Add(new SqlParameter("@Date", users.date));
cmd.Parameters.Add(new SqlParameter("@userlogged", users.userlogged));
cmd.Parameters.Add(new SqlParameter("@datelogged", users.datelogged));
int result = cmd.ExecuteNonQuery();
cmd.Dispose();
int resultado = result;
return true;
}
}
catch (Exception ex)
{
return false;
}
finally
{
connectionClose();
}
}
private bool cadastrarClient(Client client) //Is not working
{
try
{
StringBuilder query = new StringBuilder();
query.AppendFormat("insert into ClientTB (Name, Address, City, County, State, Zip_Code, CPF, Idnumber, email, celular_phone, home-phone, date_registered, login_registered)");
query.AppendFormat(" VALUES (@name, @Address, @City, @County, @State, @Zip_Code, @CPF, @Idnumber, @email, @celular_phone, @home_phone, @date_registered, @login_registered)");
connectionOpen();
using (SqlCommand cmd = connection.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = query.ToString();
cmd.Parameters.Clear();
cmd.Parameters.Add(new SqlParameter("@name", client.Name)); // All values have been received here
cmd.Parameters.Add(new SqlParameter("@Address", client.Address));
cmd.Parameters.Add(new SqlParameter("@City", client.City));
cmd.Parameters.Add(new SqlParameter("@County", client.County));
cmd.Parameters.Add(new SqlParameter("@State", client.State));
cmd.Parameters.Add(new SqlParameter("@Zip_Code", client.Zip_Code ));
cmd.Parameters.Add(new SqlParameter("@CPF", client.CPF));
cmd.Parameters.Add(new SqlParameter("@Idnumber", client.Idnumber));
cmd.Parameters.Add(new SqlParameter("@email", client.email));
cmd.Parameters.Add(new SqlParameter("@celular_phone", client.celular_phone));
cmd.Parameters.Add(new SqlParameter("@home_phone", client.home_phone));
cmd.Parameters.Add(new SqlParameter("@date_registered", client.date_registered));
cmd.Parameters.Add(new SqlParameter("@login_registered", client.login_registered)); // last line executed
int result = cmd.ExecuteNonQuery();
cmd.Dispose();
int resultado = result;
return true;
}
}
catch (Exception Ex)
{
return false;
}
finally
{
connectionClose();
}
}
#endregion Methods of Insert.
I'm using a SQL Server 2014
Bellow follows the table.
ClientID int Unchecked
Name varchar(50) Checked
Address varchar(50) Checked
City varchar(50) Checked
County varchar(50) Checked
State varchar(2) Checked
Zip_Code varchar(10) Checked
CPF varchar(14) Checked
Idnumber varchar(14) Checked
email varchar(50) Checked
celular_phone varchar(15) Checked
home_phone varchar(15) Checked
date_registered date Checked
login_registered varchar(25) Checked
Thanks for all of you.
Best Regards.
Continue reading...
I need your help once again, I'm doing exactly the same code, to insert users, and to insert clients at the SQL Server,
However the method for insert users is working, and to insert clients is not working. I've tried everything and I can't figure out where is the error.
Please help me out you guys with your remarkable knowledge, What am I doing wrong?
Thanks once again for your help.
#region Methods of Insert.
private bool cadastrarUser(User users) // Insert Uers is working perfect
{
try
{
StringBuilder query = new StringBuilder();
query.AppendFormat("insert into Users(username, loginname, [password], [date], userlogged, datelogged)");
query.AppendFormat(" VALUES (@UserName, @loginname, @password, @Date, @userlogged, @datelogged)");
connectionOpen();
using (SqlCommand cmd = connection.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = query.ToString();
cmd.Parameters.Clear();
cmd.Parameters.Add(new SqlParameter("@UserName", users.username));
cmd.Parameters.Add(new SqlParameter("@loginname", users.loginname));
cmd.Parameters.Add(new SqlParameter("@password", users.password));
cmd.Parameters.Add(new SqlParameter("@Date", users.date));
cmd.Parameters.Add(new SqlParameter("@userlogged", users.userlogged));
cmd.Parameters.Add(new SqlParameter("@datelogged", users.datelogged));
int result = cmd.ExecuteNonQuery();
cmd.Dispose();
int resultado = result;
return true;
}
}
catch (Exception ex)
{
return false;
}
finally
{
connectionClose();
}
}
private bool cadastrarClient(Client client) //Is not working
{
try
{
StringBuilder query = new StringBuilder();
query.AppendFormat("insert into ClientTB (Name, Address, City, County, State, Zip_Code, CPF, Idnumber, email, celular_phone, home-phone, date_registered, login_registered)");
query.AppendFormat(" VALUES (@name, @Address, @City, @County, @State, @Zip_Code, @CPF, @Idnumber, @email, @celular_phone, @home_phone, @date_registered, @login_registered)");
connectionOpen();
using (SqlCommand cmd = connection.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = query.ToString();
cmd.Parameters.Clear();
cmd.Parameters.Add(new SqlParameter("@name", client.Name)); // All values have been received here
cmd.Parameters.Add(new SqlParameter("@Address", client.Address));
cmd.Parameters.Add(new SqlParameter("@City", client.City));
cmd.Parameters.Add(new SqlParameter("@County", client.County));
cmd.Parameters.Add(new SqlParameter("@State", client.State));
cmd.Parameters.Add(new SqlParameter("@Zip_Code", client.Zip_Code ));
cmd.Parameters.Add(new SqlParameter("@CPF", client.CPF));
cmd.Parameters.Add(new SqlParameter("@Idnumber", client.Idnumber));
cmd.Parameters.Add(new SqlParameter("@email", client.email));
cmd.Parameters.Add(new SqlParameter("@celular_phone", client.celular_phone));
cmd.Parameters.Add(new SqlParameter("@home_phone", client.home_phone));
cmd.Parameters.Add(new SqlParameter("@date_registered", client.date_registered));
cmd.Parameters.Add(new SqlParameter("@login_registered", client.login_registered)); // last line executed
int result = cmd.ExecuteNonQuery();
cmd.Dispose();
int resultado = result;
return true;
}
}
catch (Exception Ex)
{
return false;
}
finally
{
connectionClose();
}
}
#endregion Methods of Insert.
I'm using a SQL Server 2014
Bellow follows the table.
ClientID int Unchecked
Name varchar(50) Checked
Address varchar(50) Checked
City varchar(50) Checked
County varchar(50) Checked
State varchar(2) Checked
Zip_Code varchar(10) Checked
CPF varchar(14) Checked
Idnumber varchar(14) Checked
email varchar(50) Checked
celular_phone varchar(15) Checked
home_phone varchar(15) Checked
date_registered date Checked
login_registered varchar(25) Checked
Thanks for all of you.
Best Regards.
Continue reading...