I am building a program which generates a random number in a textbox everytime the form loads.
I have this code :
public partial class Form1 : Form
{
SqlConnection c = new SqlConnection(@"Data Source=GILBERTB-PC\SQLEXPRESS;Initial Catalog=DVDandGameBooking;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter();
public Form1()
{
InitializeComponent();
random();
}
//private void button1_Click(object sender, EventArgs e)
//{
//}
public void random()
{
textBox1.Text = randomnumbers(1, 20000).ToString();
}
public int randomnumbers(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
}
}
This number generated than will be inserted in a table ShopType (in my SQL Server) in the column ShopID.
How can the program first check if there is the same number (being generated ) in the table ShopType ?