I have created main form of StockIn (StokGiris) with sub form ProductStockIn (UrunStokGiris) for my school project, I have crated the tables on SSMS created a diagram connecting id, productids together from other tables and created a Views on SSMS as vwStokGiris.
The user should be able to pick products on UrunStokGiris sub form and after closing the sub form this products should appear in main form on a datagridview I created (dgvStokGiris) then user can change the quantity of products then click “Kaydı gir” button which is last step.
The problem:
While in UrunStokGiris I am able to pick the products I want however after closing this sub form the products do not appear in the datagridview of StokGiris(dgvStokGiris). After checking the StokGiris table on SSMS I saw that all my test tries have been recorded in there (likely +10) however when clicking on vwStokGiris and executing it I saw that only 2 of them have been recorded.
the code for datagridview is below I tried to implement try catch method but catched nothing.
public void LoadStokGiris()
{
try
{
int i = 0;
dgvStokGiris.Rows.Clear();
baglanti.Open();
komut = new SqlCommand("SELECT * FROM vwStokGiris WHERE refno LIKE '" + txtRefNo.Text + "' AND durum LIKE 'Beklemede'", baglanti);
dr = komut.ExecuteReader();
while (dr.Read())
{
i++;
dgvStokGiris.Rows.Add(i, dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString(), dr[4].ToString(), dr[5].ToString(), dr[6].ToString(), dr[7].ToString());
}
dr.Close();
baglanti.Close();
Here is the code for entry button which is the last step
private void btnKaGir_Click(object sender, EventArgs e)
{
try
{
baglanti.Open();
if (dgvStokGiris.Rows.Count > 0)
{
if (MessageBox.Show("Bu kayıtları kaydetmek istediğinizden emin misiniz?", pbaslik, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
for (int i = 0; i < dgvStokGiris.Rows.Count; i++)
{
//Urün adedi güncelleme
komut = new SqlCommand("UPDATE tbUrun SET adet = adet + " + int.Parse(dgvStokGiris.Rows[i].Cells[5].Value.ToString()) + "WHERE ukodu LIKE '" + dgvStokGiris.Rows[i].Cells[3].Value.ToString() + "'", baglanti);
komut.ExecuteNonQuery();
// Stok giriş adedi güncelleme
komut = new SqlCommand("UPDATE tbStokGiris SET adet = adet + " + int.Parse(dgvStokGiris.Rows[i].Cells[5].Value.ToString()) + ", durum = 'Tamamlandi' WHERE id LIKE '" + dgvStokGiris.Rows[i].Cells[1].Value.ToString() + "'", baglanti);
komut.ExecuteNonQuery();
}
}
}
} catch (Exception ex)
{
MessageBox.Show("Hata" + ex.Message, pbaslik, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
baglanti.Close();
}
}
I tried adding try catch method for both to find any mistakes however it didn’t work.
You can dm me if you need to see the screen record of the problem and sql tables
Ferhenk Tore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.