This is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace testdb
{
public partial class AddProject : Form
{
public AddProject()
{
InitializeComponent();
}
private void btn_addproject_Click(object sender, EventArgs e)
{
string constr = @"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:/Users /Xprts_3/Documents/Database1.accdb";
string cmdstr = "insert into tb1(name,rollno,projectdate) (@First,@Last,@pdate)";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand com = new OleDbCommand(cmdstr, con);
con.Open();
com.Parameters.AddWithValue("@First", textBox_project_name.Text);
com.Parameters.AddWithValue("@Last", comboBox1_project_status.Text);
com.Parameters.AddWithValue("@pdate", dateTimePicker1.Text);
com.ExecuteNonQuery();
con.Close();
}
}
}
I am adding data to a database on button click.
Now I want validation in it. I want an error message to appear to the user if any fields are blank, instead of inserting data into the database. How may this be achieved in Windows Forms?