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
Mfwamba Tshimanga
NA
155
46.2k
Just don't repeat the same record please!
Jul 6 2014 7:55 PM
Hi!
Please I am trying to don't allow repetition of records. But I cannot resolv it.
It says it's saved but he didnt (the same datas or anothers when I open my sql server table I didnt find the record that was saved as he said).
conn = new SqlConnection(connstr);
comm = new SqlCommand();
conn.Open();
SqlParameter data = new SqlParameter("@data", SqlDbType.NChar);
SqlParameter classe = new SqlParameter("@classe", SqlDbType.NChar);
comm.Parameters.Add(data);
comm.Parameters.Add(classe);
data.Value = DateTime.Today;
classe.Value = codigoBarraStocks.Text;
comm.Connection = conn;
comm.CommandText = "select count(*) from stocks where classe = @classe";
int count = (int)comm.ExecuteScalar();
if (count == 0)
try
{
comm.ExecuteNonQuery();
MessageBox.Show("Saved succefully");
}
catch (Exception)
{
MessageBox.Show("Not saved");
}
finally
{
conn.Close();
}
Reply
Answers (
1
)
C Sharp
there is no error but it never show the report