You must Sign In to post a response.
  • Category: Windows

    Data base field type stored in two times

    using (SqlConnection connect = new SqlConnection(db.Connectionstring()))
    {
    using (SqlCommand command = new SqlCommand())
    {
    string pro = "";
    int qty;
    int totqty;

    int i=0;

    foreach (DataGridViewRow rows in dataGridView1.Rows)
    {

    SqlConnection con1 = new SqlConnection(db.Connectionstring());
    con1.Open();
    SqlCommand cmd1 = new SqlCommand("select * from sales where empnames='" + comboBox1.Text + "' ", con1);
    SqlDataReader dr = cmd1.ExecuteReader();

    if (dr.HasRows)
    {
    //while (dr.Read())
    //{
    SqlConnection con2 = new SqlConnection(db.Connectionstring());
    con2.Open();

    SqlCommand cmd2 = new SqlCommand("update sales set empnames=@empnames+'" + comboBox1.Text + "', categories=@categories, weight=@weight,per=@per,wastage=@wastage,customer=@customer,party=@party where date=@date ", con2);

    cmd2.Parameters.AddWithValue("@empnames", Convert.ToString((comboBox1.Text)));
    cmd2.Parameters.AddWithValue("@date", Convert.ToDouble(rows.Cells[0].Value));
    cmd2.Parameters.AddWithValue("@categories", Convert.ToString(rows.Cells[1].Value));
    cmd2.Parameters.AddWithValue("@weight", Convert.ToString((rows.Cells[2].Value)));
    cmd2.Parameters.AddWithValue("@per", Convert.ToDouble(rows.Cells[3].Value));
    cmd2.Parameters.AddWithValue("@wastage", Convert.ToString((rows.Cells[4].Value)));
    cmd2.Parameters.AddWithValue("@customer", Convert.ToDouble(rows.Cells[5].Value));
    cmd2.Parameters.AddWithValue("@party", Convert.ToString((rows.Cells[6].Value)));




    cmd2.ExecuteNonQuery();
    con2.Close();


    SqlConnection con4 = new SqlConnection(db.Connectionstring());
    con4.Open();
    SqlCommand cmd4 = new SqlCommand("update sales set amtcst='" + txt_netamount.Text + "', amtparty='" + txtparty.Text + "', amtfinal='" + txtfinal.Text + "' where empnames='" + comboBox1.SelectedText + "'", con4);
    cmd4.ExecuteNonQuery();
    con4.Close();

    // }
    }


    else
    {
    SqlConnection con3 = new SqlConnection(db.Connectionstring());
    con3.Open();
    SqlCommand cmd3 = new SqlCommand("insert into sales(empnames,date,categories,weight,per,wastage,customer,party,amtcst,amtparty,amtfinal)values('" + comboBox1.Text + "', '" + rows.Cells[0].Value + "','" + rows.Cells[1].Value + "','" + rows.Cells[2].Value + "','" + rows.Cells[3].Value + "','" + rows.Cells[4].Value + "','" + rows.Cells[5].Value + "','" + rows.Cells[6].Value + "','" + txt_netamount.Text + "','" + txtparty.Text + "','" + txtfinal.Text + "')", con3);
    cmd3.ExecuteNonQuery();
    con3.Close();


    }
    }

    }
    }
  • #768387
    what you mean by Data base field type stored in two times ? have you stored database field type in database ? what you want to store in database ? Please elaborate so that we can help you better
    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #768393
    It means comboBox1 it's my empnames field, in this field stored two times in data base. this is my problem.

    Delete Attachment

  • #768395
    Hi,

    In SqlCommand cmd2 you are adding the employee name twice in the update statement.
    Kindly put the debug point in the Command statement and check the value for CMD2.
    I guess in CMD2 you will get two names. It is because you are merge both the names.
    so put a debug point and let us know

    Thanks,
    Mani

  • #768396
    It means comboBox1 it's my empnames field, in this field stored two times in data base. this is my problem.

    Delete Attachment

  • #768449
    Hi,

    put a break point in your code and recheck line by line where it gets inserted duplicate entries, and same time check your SQL query for each sql statement executed in coding side.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments