1
I am trying to insert into my mysql database through Visual Studio 2017 - C# (localhost-wamppserver) but it is giving error.
The first column of the table records is the id_record which is the primary key of the table records and is auto_increment and so I did not specify it in Insert Into.
But for some reason the error is giving when inserting in the id_types that is the foreign key of the types table, I think it will be because I am using a combobox
with the values of the type-name column of the table types and inserting the records into the table records because the fields with textbox
are perfect, the error is described below and in the question title.
It will be because the values of the combobox are text and the column I am inserting is a foreign key INT?
I’m having the next mistake when inserting:
Incorrect integer value: 'TEXT' for column 'id_tipos' at row 1
My query:
string query = "INSERT INTO `registos`(`data`, `id_tipos`, `id_tec`,`id_processo`, `id_tarefa`, `horas`, `com`) VALUES ('" + datatp_1.Text + "','" + comboBox_tipo1.Text + "','" + comboBox_tec1.Text + "','" + comboBox_pro1.Text + "','" + comboBox_passos1.Text + "','" + txt_horas1.Text + "','" + txt_com1.Text + "')";
You put the second value in parentheses being that it is a
int
. What is the value you are going through? Show us thequery
graduate– Sorack
That part
'" + comboBox_tipo1.Text + "'
, you are trying to add a text where it should be an integer. Remove the'
before and after!– Marconi
What do you mean, query formed? query in Workbench?
– gmbc
Marconi removed the ' ' ' and continued to give the same friend error
– gmbc
What I would tell you is to debug your code and get the value as soon as you pass this line, then play the query in the bank and check what’s wrong.
– Marconi
Marconi has Dciscord for a more personalized help? I’m interning and I’m "new" in programming, would you help me in more detail
– gmbc
@gmbc yes, do what I told you above. Check this variable
query
by debug.– Marconi
@Marconi I’ll try now, 2minutes, if you can add in Discord it’s better: Jøycelyn#3447
– gmbc
@Marconi debugged, selected the query and now?
– gmbc
Comments here for me see the result
– Marconi
Links from Imgur : https://imgur.com/a/PznHHWa The query does not show that messagebox at the time of insertion
– gmbc
It had to be after the variable to see the result of it.
– Marconi
That’s why I asked if you had Discord Maybe it would be easier if I shared the screen, the error (messagebox)
– gmbc