Helloo,
Good day Everyone,
Can I anyone help me?
Here is my problem. I am newbies in C# development, I am Interesting to learn, searching to google and go to youtube, download lynda tutorials it's help a lot of me. But I'm on the problem that I can't not resolve. I created a form that can select or search through textbox and View in to ListView1.
I created a DBconnect.cs for the database connection:
Below is the Insert query. and I get this.
//Insert statement
public void Insert(String sql)
{
//open connection
//create command and assign the query and connection from the constructor
MySqlCommand cmd = new MySqlCommand(sql, connection);
//Execute command
cmd.ExecuteNonQuery();
//close connection
this.CloseConnection();
}
Below is the function to Insert a data to database.
form1.cs
private void Badd_Click(object sender, EventArgs e)
{
String idnumber, fname, mname, lname, email, cnumber, orcid, address, country, expertise, timepicker;
//id number
idnumber = user_aspr.Text;
fname = fname_aspr.Text;
mname = mname_aspr.Text;
lname = lname_aspr.Text;
//details
/* name = fname_aspr.Text + mname_aspr.Text + lname_aspr.Text;*/
email = email_aspr.Text;
cnumber = cnumber_aspr.Text;
orcid = orcid_aspr.Text;
address = add_aspr.Text;
country = country_aspr.Text;
//add onns
expertise = expertise_aspr.Text;
timepicker = timepicker_aspr.Text;
//ClearTextBoxes(this.Controls);
//DB Connection
DBConnect con = new DBConnect();
con.Initialize();
con.OpenConnection();
con.Insert("INSERT into tblassociation_peer_reviewer (aspr_id, aspr_fname, aspr_mname, aspr_lname, aspr_email, aspr_cnumber, aspr_orcid, address, aspr_country, aspr_experts, timepicker) values('" + idnumber + "', '" + fname + "', '" + mname + "', '" + lname + "', '" + email + "', '" + cnumber + "','" + orcid + "','" + address + "','" + country + "', '" + expertise + "', '" + timepicker + "')");
con.CloseConnection();
MessageBox.Show("Successfully Saved");
}
Problem: DBconnect.CS - Select query to form_search.cs
//Select statement
public void Select(string sql)
{
//Create Command
MySqlCommand cmd = new MySqlCommand(sql, connection);
//Create a data reader and Execute the command
MySqlDataReader dataReader = cmd.ExecuteReader();
//close Data Reader
dataReader.Close();
//close Connection
this.CloseConnection();
}
Search_form1.CS
//DB Connection
DBConnect con = new DBConnect();
con.Initialize();
con.OpenConnection();
con.Select("Select idno from where idno like "+ search_name_aspr.Text, con);
//listView code:
con.CloseConnection();
I tried a lot of codes. but's its not effective...
the purpose of my search form, when I type the TEXT in textbox, is viewinglin the listview, and double click a listview and transfer to another form.
but right now, my focus is how can I create query, when my query is seperated to another form. DBconnect.cs//
thanks,
Darryl