Results 1 to 8 of 8

Thread: [RESOLVED] when i enter the quantity nothing happend and can't add the data in database

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2020
    Posts
    20

    Resolved [RESOLVED] when i enter the quantity nothing happend and can't add the data in database

    this is my first code
    C# Code:
    1. private void GetTransno()
    2.         {
    3.             try
    4.             {
    5.                 string sdate = DateTime.Now.ToString("yyyyMMdd");
    6.                 string transno;
    7.                 int count;
    8.                 cn.Open();
    9.                 cm = new SqlCommand("select top 1 transno from tblCart where transno like '" + sdate + "%'order by id desc", cn);
    10.                 dr = cm.ExecuteReader();
    11.                 dr.Read();
    12.                 if (dr.HasRows) {
    13.                     transno = dr[0].ToString();
    14.                    count = int.Parse(transno.Substring(8, 4)) + 1;
    15.                     lbltransno.Text = sdate + (count + 1);
    16.                        
    17.                         }
    18.                 else {
    19.                     transno = sdate + "1001";
    20.                     lbltransno.Text = transno;
    21.  
    22.                 } dr.Close();
    23.                 cn.Close();
    24.             }catch (Exception ex)
    25.             {
    26.                 cn.Close();
    27.                 MessageBox.Show(ex.Message, stitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
    28.                    
    29.  
    30.                
    31.  
    32.  
    33.  
    34.             }
    35.  
    36.         }
    37.  
    38.         private void btnNew_Click(object sender, EventArgs e)
    39.         {
    40.             GetTransno();
    41.             txtsearch.Enabled = true;
    42.             txtsearch.Focus();
    43.         }
    44.  
    45.         private void txtsearch_Click_1(object sender, EventArgs e)
    46.         {
    47.  
    48.         }
    49.  
    50.         private void txtsearch_TextChanged(object sender, EventArgs e)
    51.         {
    52.             try
    53.             {
    54.                 if (txtsearch.Text == String.Empty) { return; }
    55.                 else
    56.                 {
    57.                     cn.Open();
    58.                     cm = new SqlCommand("Select * from tblproduct where pcode like'" + txtsearch.Text + "'", cn);
    59.                     dr = cm.ExecuteReader();
    60.                     dr.Read();
    61.                     if (dr.HasRows)
    62.                     {
    63.                         frmQty frm = new frmQty(this);
    64.                         frm.ProductDetails(dr["pcode"].ToString(),double.Parse(dr["price"].ToString()), lbltransno.Text);
    65.                         frm.ShowDialog();
    66.                     }
    67.                     dr.Close();
    68.                     cn.Close();
    69.                 }
    70.             }
    71.             catch (Exception ex)
    72.             {
    73.                 cn.Close();
    74.                 MessageBox.Show(ex.Message, stitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
    this is my second code

    C# Code:
    1. private string pcode;
    2.         private double price;
    3.         private String transno;
    4.         string stitle = "POS by 4B Computers";
    5.         frmPOS fpos;
    6.         public frmQty(frmPOS frmpos)
    7.         {
    8.             InitializeComponent();
    9.             cn = new SqlConnection(dbcon.MyConnection());
    10.             fpos = frmpos;
    11.         }
    12.  
    13.         private void txtQty_TextChanged(object sender, EventArgs e)
    14.         {
    15.  
    16.         }
    17.  
    18.         private void frmQty_Load(object sender, EventArgs e)
    19.         {
    20.            
    21.         }
    22.         public void ProductDetails(String pcode, double price, String transno)
    23.         {
    24.             this.pcode = pcode;
    25.             this.price = price;
    26.             this.transno = transno;
    27.  
    28.         }
    29.  
    30.         private void frmQty_KeyPress(object sender, KeyPressEventArgs e)
    31.         {
    32.             if ((e.KeyChar==13) && (txtQty.Text != String.Empty))
    33.             {
    34.                 cn.Open();
    35.                 cm = new SqlCommand("insert into tblCart (transno,pcode,price,qty,sdate)values(@transno,@pcode,@price,@qty,@sdate)", cn);
    36.                 cm.Parameters.AddWithValue("@transno", transno);
    37.                 cm.Parameters.AddWithValue("@pcode", pcode);
    38.                 cm.Parameters.AddWithValue("@price", price);
    39.                 cm.Parameters.AddWithValue("@qty", int.Parse(txtQty.Text));
    40.                 cm.Parameters.AddWithValue("@sdate", DateTime.Now);
    41.                 cm.ExecuteNonQuery();
    42.                 cn.Close();
    43.  
    44.                 this.Dispose();

    when i enter quantity or value in txtQty nothing happens or not add automatic value
    Please clear fay me
    Last edited by FunkyDexter; Dec 24th, 2020 at 03:18 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: when i enter the quantity nothing happend and can't add the data in database

    In your previous thread I posted this:
    Please don't post unformatted code. It is too hard to read.
    Please don't just post all your code. Post only what is relevant.
    and yet here we are again with a huge wad of unformatted code that is obviously largely irrelevant. If you can't be bothered to make any effort to help us, why should we make the effort to help you? I opened this thread because I wanted to help but I'm not here to be taken advantage of. Do what you can to help us help you. Narrow down the code to just what is relevant to the issue and post that formatted for readability.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2020
    Posts
    20

    Re: when i enter the quantity nothing happend and can't add the data in database

    sorry for this But my code is in two pages first code and second code and also metion it

  4. #4
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,902

    Re: when i enter the quantity nothing happend and can't add the data in database

    I've formatted the post.

    when i enter quantity or value in txtQty nothing happens or not add automatic value
    Here's your event handler for txtQty:-
    Code:
            private void txtQty_TextChanged(object sender, EventArgs e)
            {
     
            }
    It's empty so it's not surprising that it doesn't do anything.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2020
    Posts
    20

    Re: when i enter the quantity nothing happend and can't add the data in database

    Any one have soultaion Please give Answer

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: when i enter the quantity nothing happend and can't add the data in database

    Quote Originally Posted by redrose4u293 View Post
    sorry for this But my code is in two pages first code and second code and also metion it
    And look how much more obvious that is now that someone has formatted the code the way you were asked to. You say that you mentioned it but we'd have to scan through all the unformatted code to find the part that wasn't code. You could say that you didn't know when posting the first thread but you don't have that excuse this time.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Dec 2020
    Posts
    20

    Re: when i enter the quantity nothing happend and can't add the data in database

    Can you please tell me what code i enter in this txtqty

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: when i enter the quantity nothing happend and can't add the data in database

    It seems to me that the issue is likely not that TextChanged event at all. I don't see why you'd want to do anything when the Text changes, so I have to wonder why that event handler is there at all. This is what I'm talking about when I say "relevant code". How is an empty event handler relevant to us unless you specifically want something to happen on that event but, if that's the case, why are you asking us instead of telling us?

    I suspect that the actual issue is your form's KeyPress event. It seems that that is where you expect the data to be saved. Have you done any debugging at all? Have you checked to see whether that method is executed in the first place and, if it is, whether it does what you expect? Even if you don't know how to debug properly, i.e. setting breakpoints and stepping through the code, you can still do what ignorant beginners like I was do and use message boxes to or console messages to tell you what's happening. You need to do all you can for yourself first and then, if you post here, provide us with all the relevant information. I suspect that the issue is simply that you are expecting to handle keyboard events of the form but you haven't set its KeyPreview property to True. If that's the case then you proper debugging would have shown you that the KeyPress event handler was not being executed and we would have immediately known the reason when you told us that.

    If you don't know how to debug properly, stop what you're doing and learn now. It's a critical skill for all developers. In future, you need to debug your code before posting. You can then tell us exactly where and how the behaviour of your code differs from your expectation. That will make it likely that we can tell you immediately what the issue is and how to fix it. The more irrelevant stuff we have to wade through, the longer it will take, if we have the inclination at all. Debugging this should probably have taken less than half an hour and possibly much less, if you were to place a breakpoint on that event handler early and see that it wasn't hit. That's much better than our spending 24 hours to understand and/or draw out the important information.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width