Here is my code that I'm using to insert values into my database.
public void callSQL(string partNumber, string total, string numOfPacks, string dunsNumber, string serialNumber, string laneNumber)
{
MySqlConnection myConnection = new MySqlConnection("SERVER=localhost;DATABASE=testing;UID=root;PASSWORD=********;");
try
{
myConnection.Open();
Console.WriteLine(laneNumber);
MySqlCommand myCommand = new MySqlCommand("INSERT INTO test (Part_Number, total, number_of_packs, dunsNumber, serialNumber, truck_number) VALUES (" + partNumber +","+total+","+numOfPacks+","+dunsNumber+","+serialNumber+","+laneNumber+")", myConnection);
myCommand.ExecuteNonQuery();
Console.Write("Done");
myConnection.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
Its really weird what happens. The problem I am getting is with the laneNumber variable. It is a string that I read from the console.
Console.WriteLine("Please enter the date and lane number like so: ddmmyylanenumber.");
string lanenum = Console.ReadLine();
However it only gets inputted into the database when it is all numbers. The moment there is a character in there, I am not able to input anything into the database. It works when I manually change the variable to a string, but not when I use the variable with characters inside. The error I get is this:
"MySQL.Data.MySqlClient.MySqlExectipn (0x8004005): Unknown column 'whatever_i_entered_into_console' in 'field list'
The line that the compiler complains about is the myCommand.ExectueNonQuery();
line.
Hope this is enough information. Thanks for the help in advance.
EDIT truck_number is a VARCHAR.