Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
Check if record exists in DB Mysql c#
Ilyas Zahir
Jul 18 2017 1:51 PM
283
Reply
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
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
how to find all files to another destination
what is same in crop image and original image in C#?