エラーが発生します:
パラメータ値を SqlParameter から String に変換できませんでした。
私は渡します:
TestUsername,
TestPassword,
TestFirstName,
TestLastName,
TestEmail@Email.Com
コード:
try
{
Console.WriteLine("Inputs: Username, Password, First Name, Last Name, Email");
Console.WriteLine("Username: ");
string usernameInput = Console.ReadLine();
Console.WriteLine("Password: ");
string passwordInput = Console.ReadLine();
Console.WriteLine("First Name: ");
string firstNameInput = Console.ReadLine();
Console.WriteLine("Last Name: ");
string lastNameInput = Console.ReadLine();
Console.WriteLine("Email: ");
string emailInput = Console.ReadLine();
SqlCommand createLogin = new SqlCommand("INSERT INTO [dbo].[Users] VALUES ('@username', '@password', '@firstname', '@lastname', '@email')", myConnection.SqlConnection);
SqlParameter usernameParam = createLogin.Parameters.Add("@username", SqlDbType.VarChar, 40);
SqlParameter passwordParam = createLogin.Parameters.Add("@password", SqlDbType.VarChar, 50);
SqlParameter firstNameParam = createLogin.Parameters.Add("@firstname", SqlDbType.VarChar, 40);
SqlParameter lastNameParam = createLogin.Parameters.Add("@lastname", SqlDbType.VarChar, 40);
SqlParameter emailParam = createLogin.Parameters.Add("@email", SqlDbType.VarChar, 40);
usernameParam.Value = usernameInput;
passwordParam.Value = passwordInput;
firstNameParam.Value = firstNameInput;
lastNameParam.Value = lastNameInput;
emailParam.Value = emailParam;
createLogin.ExecuteNonQuery();
Console.WriteLine("Username: {0} with Password: {1} created.", usernameInput, EncDec.Decrypt(passwordInput, "testEncryption"));
}
catch (Exception CreateLoginException)
{
Console.WriteLine(CreateLoginException);
}