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 NewFurniture
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/Furniture.mdb");
OleDbCommand cmd;
OleDbDataAdapter da;
OleDbDataReader dr;
private void Button_Click(object sender, EventArgs e)
{
try
{
textBox1.Enabled = false;
int ctr, len;
string codeval, code;
DataRow drr;
con.Open();
da = new OleDbDataAdapter("select Customer_id from Customer",con);
DataSet ds1 = new DataSet();
da.Fill(ds1);
DataTable dt;
dt = ds1.Tables[0];
len = dt.Rows.Count - 1;
drr = dt.Rows[len];
code = drr["Customer_id"].ToString();
codeval = code.Substring(1, 3);
ctr = Convert.ToInt32(codeval);
if ((ctr >= 0) && (ctr < 9))
{
ctr = ctr + 1;
textBox1.Text = "C00" + ctr;
}
else if ((ctr >= 9) && (ctr < 100))
{
ctr = ctr + 1;
textBox1.Text = "C0" + ctr;
}
else if (ctr >= 99)
{
ctr = ctr + 1;
textBox1.Text = "C" + ctr;
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error..." + ex.Message);
}
}
}
}