A
adam
Hi there
I've got a littel problem. I've samo form which should add data to database.
Everythinks goes OK, but I'd like to have some alert messege when samobody
would like to add another user with the same nick. Now my aplication in that
case goes down.
This is code
void Button1_Click(object sender, EventArgs e) { SqlConnection c =
baza_danych.Polacz();
SqlCommand cmd = new SqlCommand("insert into klient
(IDklienta,Nazwisko,Imie,Adres,Miasto,Haslo) values ( '"+ IDklienta.Text +"'
,'" + Nazwisko.Text + "','" + Imie.Text + "','" + Adres.Text + "','" +
Miasto.Text + "','" + Haslo.Text + "')", c);
SqlDataReader dr = cmd.ExecuteReader();
bool test; test=dr.HasRows; if (test==true) { dr.Read(); Label1.Text =
"choose another nick"; } else { Label1.Text = "You are added to database"; }
dr.Close();
c.Close(); }
TIA
Adam
I've got a littel problem. I've samo form which should add data to database.
Everythinks goes OK, but I'd like to have some alert messege when samobody
would like to add another user with the same nick. Now my aplication in that
case goes down.
This is code
void Button1_Click(object sender, EventArgs e) { SqlConnection c =
baza_danych.Polacz();
SqlCommand cmd = new SqlCommand("insert into klient
(IDklienta,Nazwisko,Imie,Adres,Miasto,Haslo) values ( '"+ IDklienta.Text +"'
,'" + Nazwisko.Text + "','" + Imie.Text + "','" + Adres.Text + "','" +
Miasto.Text + "','" + Haslo.Text + "')", c);
SqlDataReader dr = cmd.ExecuteReader();
bool test; test=dr.HasRows; if (test==true) { dr.Read(); Label1.Text =
"choose another nick"; } else { Label1.Text = "You are added to database"; }
dr.Close();
c.Close(); }
TIA
Adam