Click here to Skip to main content
15,911,890 members
Home / Discussions / C#
   

C#

 
GeneralRe: Why does the Form_Paint event run continuously and only draw once ? Pin
Dave Kreskowiak24-Oct-19 18:04
mveDave Kreskowiak24-Oct-19 18:04 
GeneralC # Pin
Member 1461982622-Oct-19 0:45
Member 1461982622-Oct-19 0:45 
GeneralRe: C # Pin
OriginalGriff22-Oct-19 0:57
mveOriginalGriff22-Oct-19 0:57 
QuestionRe: C # Pin
ZurdoDev22-Oct-19 2:59
professionalZurdoDev22-Oct-19 2:59 
AnswerRe: C # Pin
OriginalGriff22-Oct-19 3:32
mveOriginalGriff22-Oct-19 3:32 
GeneralRe: C # Pin
ZurdoDev22-Oct-19 4:04
professionalZurdoDev22-Oct-19 4:04 
GeneralRe: C # Pin
Dave Kreskowiak22-Oct-19 6:07
mveDave Kreskowiak22-Oct-19 6:07 
GeneralRe: C # Pin
Luc Pattyn22-Oct-19 10:23
sitebuilderLuc Pattyn22-Oct-19 10:23 
Assuming you have some MySQL database with the appropriate table the codes may look like this:

C#
public List<string> GetAnswers(string question) {
	List<string> answers=new List<string>();
	string connectionString=@"SERVER=localhost;DATABASE=myDatabase;UID=me;PASSWORD=1234;";
	try {
		using (MySqlConnection dbCon=new MySqlConnection(connectionString)) {
			dbCon.Open();
			// to avoid someone starting a lecture about SQLinjection:
			question=question.Split(';')[0];
			string query="SELECT answer FROM AnswersToAllQuestions "+
				" WHERE question LIKE '%"+question+"%'";
			using (MySqlCommand dbCmd=new MySqlCommand(query, dbCon)) {
				using (MySqlDataReader reader=dbCmd.ExecuteReader()) {
					while (reader.Read()) {
						string answer=(string)reader["answer"];
						answers.Add(answer);
					}
				}
			}
			dbCon.Close();
		}
	} catch (Exception exc) {
		Console.WriteLine(exc.ToString());
	}
	return answers;
}

For other databases, some minor modifications would be needed.
Reading an article or a book on database access might be a good starter...

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum


modified 22-Oct-19 16:47pm.

GeneralRe: C # Pin
Richard Deeming23-Oct-19 1:25
mveRichard Deeming23-Oct-19 1:25 
GeneralRe: C # Pin
Luc Pattyn23-Oct-19 2:56
sitebuilderLuc Pattyn23-Oct-19 2:56 
QuestionLDAP query to ActiveDirectory being whimsical (search by custom attribute broken) Pin
Super Lloyd21-Oct-19 21:30
Super Lloyd21-Oct-19 21:30 
SuggestionRe: LDAP query to ActiveDirectory being whimsical (search by custom attribute broken) Pin
Richard MacCutchan21-Oct-19 22:41
mveRichard MacCutchan21-Oct-19 22:41 
GeneralRe: LDAP query to ActiveDirectory being whimsical (search by custom attribute broken) Pin
Super Lloyd22-Oct-19 1:07
Super Lloyd22-Oct-19 1:07 
GeneralRe: LDAP query to ActiveDirectory being whimsical (search by custom attribute broken) Pin
Richard MacCutchan22-Oct-19 1:31
mveRichard MacCutchan22-Oct-19 1:31 
Questiona WinForm ToolStripMenuItem quirk ? Pin
BillWoodruff21-Oct-19 4:26
professionalBillWoodruff21-Oct-19 4:26 
AnswerRe: a WinForm ToolStripMenuItem quirk ? Pin
Luc Pattyn21-Oct-19 9:14
sitebuilderLuc Pattyn21-Oct-19 9:14 
AnswerRe: a WinForm ToolStripMenuItem quirk ? Pin
Richard Deeming22-Oct-19 0:41
mveRichard Deeming22-Oct-19 0:41 
GeneralRe: a WinForm ToolStripMenuItem quirk ? Pin
BillWoodruff22-Oct-19 0:48
professionalBillWoodruff22-Oct-19 0:48 
GeneralRe: a WinForm ToolStripMenuItem quirk ? Pin
Richard Deeming22-Oct-19 1:07
mveRichard Deeming22-Oct-19 1:07 
GeneralRe: a WinForm ToolStripMenuItem quirk ? Pin
BillWoodruff22-Oct-19 19:04
professionalBillWoodruff22-Oct-19 19:04 
Question'Access to the path 'F:\System Volume Information' is denied.' Pin
Member 1405587919-Oct-19 8:45
Member 1405587919-Oct-19 8:45 
AnswerRe: 'Access to the path 'F:\System Volume Information' is denied.' Pin
Eddy Vluggen19-Oct-19 11:11
professionalEddy Vluggen19-Oct-19 11:11 
GeneralRe: 'Access to the path 'F:\System Volume Information' is denied.' Pin
Member 1405587920-Oct-19 2:43
Member 1405587920-Oct-19 2:43 
GeneralRe: 'Access to the path 'F:\System Volume Information' is denied.' Pin
Eddy Vluggen20-Oct-19 4:53
professionalEddy Vluggen20-Oct-19 4:53 
GeneralRe: 'Access to the path 'F:\System Volume Information' is denied.' Pin
Dave Kreskowiak20-Oct-19 4:59
mveDave Kreskowiak20-Oct-19 4:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.