I don't know if I am going about this entirely the wrong way but I have been following tutorials and created a small database application that connects to a SQL database (database of names / jobs).
I have an if statement that activates via a combo box which allows the user to pick which details they want to search on via a drop down box. I did have this initially setup as a method which later called the code within the same form which works perfectly.
What I would like to do is to take my method onto a seperate page (another class?) to tidy up my form. I don't really understand how I reference my buttons etc.. from form1 onto my new class List_Methods:
Extract of what i'm trying to do:
Form1.cs
if (comboBox1.Text == "First Name")
{
List_Methods Firstnameselecton = new List_Methods();
// Firstnameselecton();
}
List_Methods.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SQLDatabase
{
class List_Methods
{
Form1 Form1_Load;
Form1_Load = new Form1();
private void Firstnameselecton()
{
string searchFor = richTextBox4.Text;
int results = 0;
DataRow[] returnedRows;
returnedRows = ds1.Tables["Workers"].Select("first_name like '" + searchFor + "%'");
results = returnedRows.Length;
if (results > 0)
{
DataRow dr1;
dr1 = returnedRows[0];
MessageBox.Show(dr1["first_name"].ToString() + " " + dr1["last_name"].ToString() + ", Job Title: " + dr1["Job_Title"].ToString());
}
else
{
MessageBox.Show("No Record");
}
}
}
}

New Topic/Question
Reply



MultiQuote






|