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
Mehboob Ali
NA
25
3.1k
Query creates duplicate entries in SQL server
Mar 1 2016 1:16 AM
On click below code creates 4 entries of same data.
private void button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("insert into class ([className],[mfee],[adfee],[status],[date] )values('" + textBox1.Text + "', '" + textMfee.Text + "', '" + textAdfee.Text + "', '" + comboBox1.SelectedItem.ToString() + "', @Date )", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DateTime ndt = DateTime.ParseExact(textDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
cmd.Parameters.AddWithValue("@Date", ndt);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("Class Name already exist");
}
else
{
SqlDataAdapter sda0 = new SqlDataAdapter(cmd);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
DataTable dt0 = new DataTable();
sda0.Fill(dt0);
MessageBox.Show("New Class added");
}
Reply
Answers (
4
)
change date time picker to show UTC instead of local time
purpose of "This" keywords