Now, how to to get only value of Name, and only value of Surname.
I tried like the following code, but I get an error(invalidargument=value of '1' is not valid for 'index'. parameter name: index)
DataGridViewCell cell = null;
foreach (DataGridViewCell selectedCell in dataGridView1.SelectedCells)
{
cell = selectedCell;
break;
}
if (listBox1.Items == null)
{
MessageBox.Show("Please, select an Employee!");
}
else
{
string str = "";
for (int i = 0; i <= listBox1.Items.Count-1; i++)
{
if (listBox1.Items[i] != null)
{
if (str == "")
{
str = listBox1.Items[i].ToString();
}
else
{
str += "," + listBox1.Items[i].ToString();
}
}
}
cmd.Parameters.AddWithValue("@empName", listBox1.Items[0].ToString());
cmd.Parameters.AddWithValue("@empSurname", listBox1.Items[1].ToString());