2 Replies - 324 Views - Last Post: 15 October 2012 - 08:09 AM Rate Topic: -----

#1 chenaz  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-November 11

add selected item to DGV

Posted 15 October 2012 - 06:35 AM

Hi all

    for (int i = 0; i < dgv_Detail.Rows.Count - 1; i++)
                {


                    conn = new SqlConnection(connectionstring);
                    conn.Open();
                    da = new SqlDataAdapter("select * from asset where asset_no='" + txt_Barcode.Text + "'", conn);
                    Assetdt = new DataTable();

                    da.Fill(Assetdt);
                    dgv_Detail.DataSource = Assetdt;

                }

i wanna noe why this does not give me a loop for my dgvtable.
and how do i make it like, after i key in a asset_no and hit enter, instead of over writing the first data that i enter, i wan it to add on to the table and so on after i add every item on it.

thanks all

Is This A Good Question/Topic? 0
  • +

Replies To: add selected item to DGV

#2 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4490
  • View blog
  • Posts: 7,822
  • Joined: 08-June 10

Re: add selected item to DGV

Posted 15 October 2012 - 08:02 AM

This is a complete mess. First of all: learn how to properly write queries.

Second, I think you've got your logic inside out. You're trying to loop through rows that must not exist yet, and trying to fill the data source over and over again (just filling it once is enough).

If I've gotten that wrong, it's because your question is confusing and broken. Please explain more clearly and in more detail what you're trying to accomplish.
Was This Post Helpful? 0
  • +
  • -

#3 chenaz  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-November 11

Re: add selected item to DGV

Posted 15 October 2012 - 08:09 AM

View PostCurtis Rutland, on 15 October 2012 - 08:02 AM, said:

This is a complete mess. First of all: learn how to properly write queries.

Second, I think you've got your logic inside out. You're trying to loop through rows that must not exist yet, and trying to fill the data source over and over again (just filling it once is enough).

If I've gotten that wrong, it's because your question is confusing and broken. Please explain more clearly and in more detail what you're trying to accomplish.

hi there, thanks for the link, a moment ago i already read the link haha. but my first objective is to solve this loop first.

i wan to select an item from database and show it in my DGV.
my current code only show one result after i input the asset_no.
everytime i input new asset_no, the new result will overwrite old one.
how do i make a loop that will not overwrite the first result? then the DGV will show the both first,second and so on result untill i close the application

But if i put fill datasource outside of the loop, same result, it will still over write the previous result.
and code below does not give me any results.
for (int i = 0; i < dgv_Detail.Rows.Count - 1; i++)


i have to change to
for (int i = 0; i < dgv_Detail.Rows.Count + 1; i++)


then it will result one result only. i wan my DGV to continue to show my result as in put in inputs

This post has been edited by chenaz: 15 October 2012 - 08:13 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1