How to Retrieve OLedb data and show it to MessageBox

Apr 23 2018 12:33 PM
Here i did some code to retieve the data from my Oledb and show it via MessageBox But i didn't get the exact output:
---------------------------------------------------------------
Code:
---------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace AutomaticPrescriptionSystem
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
OleDbConnection con1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\db\\Pres.mdb;");
OleDbCommand cmd1 = con1.CreateCommand();
con1.Open();
cmd1.CommandText = "Select * From advice Where bp='" + this.textBox1.Text + "' and heartrate='" + this.textBox2.Text + "'";
cmd1.Connection = con1;
// cmd1.ExecuteNonQuery();
OleDbDataReader mReader = cmd1.ExecuteReader();
int count = 0;
while (mReader.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("Advice " + cmd1);
}
else
{
MessageBox.Show("incorrect");
}
}
catch (Exception)
{
Console.WriteLine("no connection");
}
}
}
}
 

Brought to you by:

Answers (1)