-
Dec 23rd, 2020, 12:08 PM
#1
Thread Starter
Junior Member
[RESOLVED] when i enter the quantity nothing happend and can't add the data in database
this is my first code
C# Code:
private void GetTransno()
{
try
{
string sdate = DateTime.Now.ToString("yyyyMMdd");
string transno;
int count;
cn.Open();
cm = new SqlCommand("select top 1 transno from tblCart where transno like '" + sdate + "%'order by id desc", cn);
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows) {
transno = dr[0].ToString();
count = int.Parse(transno.Substring(8, 4)) + 1;
lbltransno.Text = sdate + (count + 1);
}
else {
transno = sdate + "1001";
lbltransno.Text = transno;
} dr.Close();
cn.Close();
}catch (Exception ex)
{
cn.Close();
MessageBox.Show(ex.Message, stitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void btnNew_Click(object sender, EventArgs e)
{
GetTransno();
txtsearch.Enabled = true;
txtsearch.Focus();
}
private void txtsearch_Click_1(object sender, EventArgs e)
{
}
private void txtsearch_TextChanged(object sender, EventArgs e)
{
try
{
if (txtsearch.Text == String.Empty) { return; }
else
{
cn.Open();
cm = new SqlCommand("Select * from tblproduct where pcode like'" + txtsearch.Text + "'", cn);
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
frmQty frm = new frmQty(this);
frm.ProductDetails(dr["pcode"].ToString(),double.Parse(dr["price"].ToString()), lbltransno.Text);
frm.ShowDialog();
}
dr.Close();
cn.Close();
}
}
catch (Exception ex)
{
cn.Close();
MessageBox.Show(ex.Message, stitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this is my second code
C# Code:
private string pcode;
private double price;
private String transno;
string stitle = "POS by 4B Computers";
frmPOS fpos;
public frmQty(frmPOS frmpos)
{
InitializeComponent();
cn = new SqlConnection(dbcon.MyConnection());
fpos = frmpos;
}
private void txtQty_TextChanged(object sender, EventArgs e)
{
}
private void frmQty_Load(object sender, EventArgs e)
{
}
public void ProductDetails(String pcode, double price, String transno)
{
this.pcode = pcode;
this.price = price;
this.transno = transno;
}
private void frmQty_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar==13) && (txtQty.Text != String.Empty))
{
cn.Open();
cm = new SqlCommand("insert into tblCart (transno,pcode,price,qty,sdate)values(@transno,@pcode,@price,@qty,@sdate)", cn);
cm.Parameters.AddWithValue("@transno", transno);
cm.Parameters.AddWithValue("@pcode", pcode);
cm.Parameters.AddWithValue("@price", price);
cm.Parameters.AddWithValue("@qty", int.Parse(txtQty.Text));
cm.Parameters.AddWithValue("@sdate", DateTime.Now);
cm.ExecuteNonQuery();
cn.Close();
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.
-
Dec 23rd, 2020, 10:33 PM
#2
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.
-
Dec 24th, 2020, 01:02 AM
#3
Thread Starter
Junior Member
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
-
Dec 24th, 2020, 03:22 AM
#4
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
-
Dec 24th, 2020, 03:32 AM
#5
Thread Starter
Junior Member
Re: when i enter the quantity nothing happend and can't add the data in database
Any one have soultaion Please give Answer
-
Dec 24th, 2020, 04:47 AM
#6
Re: when i enter the quantity nothing happend and can't add the data in database
Originally Posted by redrose4u293
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.
-
Dec 24th, 2020, 10:50 AM
#7
Thread Starter
Junior Member
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
-
Dec 24th, 2020, 11:35 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|