TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ilyas Zahir
NA
86
25.2k
Check if record exists in DB Mysql c#
Jul 18 2017 1:51 PM
hi experts my code is like that check on table1 if textbox1.Text exist if yes go to table2 and check if textbox1.text exist and if textbox2.Text exist if they exist open the form if not insert them and open the form and if textbox1.text exist and textbox2.text doesn't exist close form
i wrote this :
MySqlConnection con =
new
MySqlConnection(connectionString);
i = 0;
con.Open();
MySqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText =
"select * from informat where u_ser = '"
+ metroTextBox2.Text +
"' "
;
cmd.ExecuteNonQuery();
DataTable dt =
new
DataTable();
MySqlDataAdapter da =
new
MySqlDataAdapter(cmd);
da.Fill(dt);
i = dt.Rows.Count;
int
userial = metroTextBox2.Text.Length;
if
(userial >= 5 || metroTextBox2.Text ==
null
)
{
MySqlConnection conet =
new
MySqlConnection(connectionString);
conet.Open();
MySqlCommand cmsd = conet.CreateCommand();
cmsd.CommandType = CommandType.Text;
cmsd.CommandText =
"select * from alred where u_ser = '"
+ metroTextBox2.Text +
"'and u_ip = '"
+ textBox1.Text +
"'"
;
cmsd.ExecuteNonQuery();
DataTable ddts =
new
DataTable();
MySqlDataAdapter ddas =
new
MySqlDataAdapter(cmsd);
ddas.Fill(ddts);
if
(textBox1.Text !=
null
)
{
MessageBox.Show(
"Your Serial is used in another computer"
);
this
.Close();
}
else
if
(metroTextBox2.Text ==
null
& textBox1.Text ==
null
)
{
ireview frms =
new
ireview();
this
.Hide();
frms.Show();
}
else
if
(metroTextBox2.Text !=
null
&& textBox1.Text !=
null
)
{
MySqlConnection conect =
new
MySqlConnection(connectionString);
conect.Open();
MySqlCommand cmsdd = conet.CreateCommand();
cmsdd.CommandType = CommandType.Text;
cmsdd.CommandText =
"INSERT INTO alred (u_ser, u_ip) "
+
" Values ('"
+ metroTextBox2.Text +
"', '"
+ textBox1.Text +
"')"
;
cmsdd.ExecuteNonQuery();
DataTable sddts =
new
DataTable();
MySqlDataAdapter sddas =
new
MySqlDataAdapter(cmsdd);
sddas.Fill(sddts);
ireview frms =
new
ireview();
this
.Hide();
frms.Show();
}
}
else
{
MessageBox.Show(
"You Serial Doesn't Exist"
);
}
}
but it doesn't work its always go directly to insert and it insert it two times
Reply
Answers (
3
)
how to find all files to another destination
what is same in crop image and original image in C#?