I am looking to compare the input on a windows form textbox to a field in a database. The table is 'products' and the field is 'ReOrderlevel'. If the value entered into the text box is less than the ReOrderlevel, I need a message box to show 'Please Order Now'. I am completely new to C# and not sure if any of this will make sense but I will put my effort below in case anyone can work out what I am going on about! Thank you so much in advance !
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 MySql.Data.MySqlClient;
using System.Text.RegularExpressions;
namespace rescue_centre
{
public partial class FrmStock : Form
{
public FrmStock()
{
InitializeComponent();
}
private void FrmStock_Load(object sender, EventArgs e)
{
refresh_data();
}
public void refresh_data()
{
string Query = "select * from stock";
MySqlConnection mycon = new MySqlConnection("datasource=localhost;username=root;password='';database=fsd;"); MySqlCommand cmd = new MySqlCommand(Query, mycon);
MySqlDataAdapter adapter = new MySqlDataAdapter();
MySqlDataReader Mdr;
adapter.SelectCommand = cmd;
DataTable dTable1 = new DataTable();
adapter.Fill(dTable1);
DtgStock.DataSource = dTable1;
mycon.Open();
Query = "Select * from stock";
cmd = new MySqlCommand(Query, mycon);
Mdr = cmd.ExecuteReader();
CmbPrd.Items.Clear();
while (Mdr.Read())
{
CmbPrd.Items.Add(Mdr.GetString("ProdCode"));
}
mycon.Close();
mycon.Open();
Query = "Select * from stock";
cmd = new MySqlCommand(Query, mycon);
Mdr = cmd.ExecuteReader();
CmbLoc.Items.Clear();
while (Mdr.Read())
{
CmbLoc.Items.Add(Mdr.GetString("LocCode"));
}
mycon.Close();
}
private void QtyTxt_Validating(object sender, CancelEventArgs e)
{
string query = "Select ReOrderlevel from Product where (ProdCode)='" + CmbPrd.Text + "';";
MySqlConnection mycon = new MySqlConnection("datasource=localhost;username=root;password='';database=fsd");
MySqlCommand cmd = new MySqlCommand(query, mycon);
if
QtyTxt.Text<ReOrderLevel
MessageBox.Show("Stock Low Please Order Now")
mycon.Open();
cmd.ExecuteNonQuery();
mycon.Close();
refresh_data();
HelperClassto open DB and execute your queries. And where is yourReOrderLevelresult to compareQtyTxt.Text<ReOrderLevel?