Kostakis45
Active member
- Joined
- Apr 3, 2022
- Messages
- 37
- Programming Experience
- Beginner
Hello everyone.After some organizing in my code(It WAS a mess.Everything in one file).I'm having a problem with a specific reference.
To explain it with words first before jumping to code.
In my main Form there is a method with KeyEventArgs so that when the Enter Key is pressed a string is gonna take a value from TextBox.
Ofter organizing my code I made a lot new cs files and managed to reference each to my main Form except one class that is for searching the database.
I'm trying to refernce to from Database_Search.cs to the method with KeyEventArgs in my main form.
Bellow I'll show you some attempts I did with only one not giving me an error but not getting the value from TextBox.
The 1st attempt doesn't give errors but it's not getting the value.
So my question is how can I reference to that method so that i can pass the search_valu to my database?
To explain it with words first before jumping to code.
In my main Form there is a method with KeyEventArgs so that when the Enter Key is pressed a string is gonna take a value from TextBox.
Ofter organizing my code I made a lot new cs files and managed to reference each to my main Form except one class that is for searching the database.
I'm trying to refernce to from Database_Search.cs to the method with KeyEventArgs in my main form.
Bellow I'll show you some attempts I did with only one not giving me an error but not getting the value from TextBox.
Search Method from Main Form:
public void Search_Box_KeyDown(KeyEventArgs e)//Πατώντας το ENTER
{
if(e.KeyCode == Keys.Enter)
{
string search_values = Search_Box.Text;
}
Database_Search ds = new Database_Search();
ds.Search_The_Database_Enter(e);
}
1st attempt.This code is in the Database_Search.cs:
public void Search_The_Database_Enter(KeyEventArgs e)
{
Plasteka pa = new Plasteka();//My main Form
if (e.KeyCode == Keys.Enter)
{
string search_values = pa.Search_Box.Text;//Dunno if this line should be inside if statement // Τιμή από το Search_Box
pa.tabControl1.Visible = true;
var con = new SQLiteConnection(connection);
con.Open();
var cmd = new SQLiteCommand(con);
cmd.CommandText = "SELECT * FROM Description WHERE Mould_Code = '" + search_values + "'";
SQLiteDataReader reader = cmd.ExecuteReader();
reader.Read();
//Περιγραφή
pa.mould_code_input.Text = reader["Mould_Code"].ToString();
pa.machine_number_input.Text = reader["Machine_Number"].ToString();
pa.machine_type_input.Text = reader["Machine_Type"].ToString();
pa.supplier_input.Text = reader["Supplier"].ToString();
pa.colour_input.Text = reader["Colour"].ToString();
pa.comboBox1.Text = reader["Plastic_Type_1"].ToString();
pa.comboBox2.Text = reader["Plastic_Type_2"].ToString();
pa.comboBox3.Text = reader["Plastic_Type_3"].ToString();
pa.numericUpDown1.Text = reader["Plastic_Type_1_Val"].ToString();
pa.numericUpDown2.Text = reader["Plastic_Type_2_Val"].ToString();
pa.numericUpDown3.Text = reader["Plastic_Type_3_Val"].ToString();
pa.dateTimePicker1.Text = reader["Date_Time"].ToString();
pa.item_name_input.Text = reader["Item_Name"].ToString();
byte[] Image_1 = (byte[])reader["Image_1"];
pa.pictureBox1.Image = ConvertBytesToImage(Image_1);
byte[] Image_2 = (byte[])reader["Image_2"];
pa.pictureBox2.Image = ConvertBytesToImage(Image_2);
}
}
2nd attempt.Gives conversion Error Void to String.Fully Understandable.:
string search_values = pa.Search_Box_KeyDown(search_values)
3d attempt.Gives error that i can't use (.) in void.I get that too.:
cmd.CommandText = "SELECT * FROM Description WHERE Mould_Code = '" + pa.Search_Box_KeyDown(e).search_values; + "'";
The 1st attempt doesn't give errors but it's not getting the value.
So my question is how can I reference to that method so that i can pass the search_valu to my database?
Last edited: