2
Answers

how to upload Video in database in and play in asp.net with

Photo of krishna pandey

krishna pandey

11y
9.7k
1

Answers (2)

0
Photo of Bhushan Gawale
NA 9.7k 1.1m 10y
The straight forward approach to avoid duplicates will be to check if same record exists in database before triggering the insert statement.

Something like

var result = select * from table where primarykey='a';
if(result.Count==0)
{
        //your logic to insert a record in the database
}



0
Photo of Sheffer Fernandes
NA 15 2.2k 10y
see my code is for attendance marking and saving in access db
but my issue is that if the user marks the same attendance twice on the same day then duplicate values get stored fr eg. a,b,c,ds attendance are marked and saved for today,then if the user trys to mark attendance again for today then i dont  want to allow him to mark the attendance
this is the code:
  private void button1_Click(object sender, EventArgs e)
        {
           
            OleDbCommand command = new OleDbCommand();
            command.Connection = connect;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                connect.Open();
                command.CommandText = "select WorkerName from AttendanceTable where AttendanceDate=Date()";
                OleDbDataReader reader = command.ExecuteReader();
               // MessageBox.Show(reader["WorkerName"].ToString());
                int count=0;
               
                while (reader.Read())
                {
                    count++;
                }
                connect.Close();
                        if (row.Cells[1].Value != null)
                        {
                            if ((Boolean)row.Cells[1].Value == true)
                            {
                                try
                                {
                                    connect.Open();

                                    string a = Convert.ToString(row.Cells[0].Value.ToString());
                                    int b = Convert.ToInt32(row.Cells[1].Value = -1);

                                    command.CommandText = "insert into AttendanceTable(WorkerName,AttendanceDate,AtWork) values('" + a + "','" + dateTimePicker1.Text + "','" + b + "')";

                                    command.ExecuteNonQuery();

                                }

                                catch (Exception ex)
                                {
                                    MessageBox.Show("Error" + ex);

                                }

                            }

                            if ((Boolean)row.Cells[1].Value == false)
                            {
                                try
                                {
                                    connect.Open();

                                    string a = Convert.ToString(row.Cells[0].Value.ToString());
                                    int b = Convert.ToInt32(row.Cells[1].Value = 0);



                                    command.CommandText = "insert into AttendanceTable(WorkerName,AttendanceDate,AtWork) values('" + a + "','" + dateTimePicker1.Text + "','" + b + "')";


                                    command.ExecuteNonQuery();

                                }

                                catch (Exception ex)
                                {
                                    MessageBox.Show("Error" + ex);

                                }

                            }
                        }

                        connect.Close();
                        if (count == 1)
                        {
                            MessageBox.Show("Data Saved");

                        }

                        else if (count > 1)
                        {
                            MessageBox.Show("Duplictate Records");
                        }
 
            }
          
        }
0
Photo of Bhushan Gawale
NA 9.7k 1.1m 10y
Great!! glad to know that you solved your problem, it would be great if you share the solution here so that alike will be benefited.

About your new issue, can you explain in details what duplicates you are referring to?
0
Photo of Sheffer Fernandes
NA 15 2.2k 10y
i solved the connection error but still dupliacte values r getting stored can ull plz help me in this
0
Photo of Bhushan Gawale
NA 9.7k 1.1m 10y
All right, I would recommend you should get started with basics of ADO.NET first which will help you to understand basic concepts in better way!!

http://www.codeproject.com/Articles/8477/Using-ADO-NET-for-beginners

You can also refer the documentation of best practices in ADO.NET e.g. for using connection objects
https://msdn.microsoft.com/en-us/library/ms971481.aspx#adonetbest_topic5
0
Photo of Sheffer Fernandes
NA 15 2.2k 10y
i'm actually new to programming so i dont knw many things so can u be a little more specific Mr  Bhushan
0
Photo of Bhushan Gawale
NA 9.7k 1.1m 10y
Have you tried making use of the using block?

something like

using(OldeDbConnection connection = new OldeDbConnection(....))
{
    //your code
}