I have created a Windows Form App which is connected to a database and users enter specific values in it. The problem I'm facing right now is that I created a search, which works like charm. But, users will always search by Name and Surname, and I wanted to trim this search to be more accuarate. It works, but when I enter only Name or only Surname, I'd like to show a massageBox to say that they didn't enter properly. So I wrote this, but if I type only one word, it crashes and shows this error: Index was outside the bounds of array. Thanks !
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length != 0)
{
var numePrenume = textBox1.Text.Trim().Split(' ');
var nume = numePrenume[0];
var prenume = numePrenume[1];
if (nume.Length > 0 || prenume.Length > 0)
{
var connString = @"Data Source=C:\Users\Andrei\Documents\Visual Studio 2010\Projects\Stellwag\Stellwag\Angajati.sdf";
using (var conn = new SqlCeConnection(connString))
{
}
}
//some code
}