Friday, October 25, 2013

Getting to Know in C#

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 BaddClick(object sender, EventArgs e) { String idnumber, fname, mname, lname, email, cnumber, orcid, address, country, expertise, timepicker; //id number idnumber = useraspr.Text; fname = fnameaspr.Text; mname = mnameaspr.Text; lname = lnameaspr.Text; //details /* name = fnameaspr.Text + mnameaspr.Text + lnameaspr.Text;*/ email = emailaspr.Text; cnumber = cnumberaspr.Text; orcid = orcidaspr.Text; address = addaspr.Text; country = countryaspr.Text; //add onns expertise = expertiseaspr.Text; timepicker = timepickeraspr.Text; //ClearTextBoxes(this.Controls); //DB Connection DBConnect con = new DBConnect(); con.Initialize(); con.OpenConnection(); con.Insert("INSERT into tblassociationpeerreviewer (asprid, asprfname, asprmname, asprlname, aspremail, asprcnumber, asprorcid, address, asprcountry, asprexperts, 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 formsearch.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(); }



Searchform1.CS



//DB Connection DBConnect con = new DBConnect(); con.Initialize(); con.OpenConnection(); con.Select("Select idno from where idno like "+ searchnameaspr.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
Full Post

No comments:

Post a Comment