can't add multiple data in datagridview

tquereshi22

Member
Joined
Apr 20, 2007
Messages
8
Programming Experience
Beginner
Hi all i am having problem working with datagridview. I am creating a Point of sale system and basically i created a text box and a button. When i type in a product id and hit the button, the datagridview will return the name of the item and the price. The problem is when i typed in 2 for product id 2, the product id 1 is still added to the list, even when i leave the field blank it still does the same thing? how do i solve this problem?

Private Sub cmdGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdGo.Click

da.SelectCommand = cmd
da.SelectCommand.Parameters.AddWithValue("@ProductID", txtInv.Text)
da.Fill(ds)

DataGridView1.DataSource = ds.Tables(0)


End Sub


Private Sub POSForm3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
da.SelectCommand = cmd
da.SelectCommand.Parameters.AddWithValue("@ProductID", "*")
da.Fill(ds)


DataGridView1.DataSource = ds.Tables(0)
ds.Tables(0).Rows.Clear()
End Sub


Another question is how do i calculate the total of the price in the datagridview and also how do i when i click on save transaction the quantity of an item from the database; QOH will be from 24 to 22 if 2 chocolate for example was bought.

Please help as i need to get this done as soon as possible. Some coding would be nice to give me an idea of how the whole thing works.

Jon

Oh one more thing im using vb 2005 and ms access
 
Hi m8, in response to your Selecting records where only equal to the value of your textbox, may i recommend as follows.

ok i'll attempt a quick step by step guide separate to what you have done just so you can see the other way of doing it :D

1.) GO to datascources and add a new data source
2.) Complete datascource wizard adding the table in question
3.) Edit that Datascource in the designer
4.) You will have a box with your tables fields and attached to that box a tableadapter with 'Fill,GetData()' in it
5.) Right Click on Fill,GetData() and click 'Add Query'
6.) Use normal Select Except When you get to the Query Window add onto the end: 'WHERE ProductID = @ProductID'
7.) Click Next And call this new Query FillByProductID GetDatabyProductID etc.
8.) This allows you to use different selects for the form depending on its use, utilising the new object orientated approach.
9.) Add A Datagrid to the Form using your new data source, and your textbox and button.
10.) OK on your button put code like:

VB.NET:
[COLOR=black]Me.TblExampleTableAdapter.FillByProductID(Me.dsExample.tblExample, Me.ToolStripComboBox1.Text)[/COLOR]


See what we do here? we fill the datagrid automatically here now using the new FillByProductID query and specifying the @Parameter as the Text Property of your text box.

Very Simple :D



UPDATE: also check out the DW2 link on Cjards Sig, and click walkthrough "Walkthrough: Creating a Form to Search Data in a Windows Application"
 
Last edited:
Hi thanks for the help. Is the toolstripcombobox1.text, s'pose to be a text box or a toolstrip control? if it is either the toolstrip or text box i still get this error message

VB.NET:
Error    1    Too many arguments to 'Public Overridable Overloads Function FillByProductID(dataTable As snowwhiteDataSet.tblPRODUCTDataTable) As Integer'.
 
Hi the fillby query is this

VB.NET:
SELECT        PRODUCTID, DESCRIPTION, PRICE
FROM            tblPRODUCT
WHERE        PRODUCTID = @ PRODUCTID

and the button code is@

VB.NET:
Me.TblPRODUCTTableAdapter.FillByProductID(Me.SnowwhiteDataSet.tblPRODUCT, Me.toolstripcombobox1.Text)
 
Infact (pardon the double post) in your sqlquery is there a space between @ and the word productID?

if so, this is wrong it should be one word as follows:

@PRODUCTID
 
Hi no there's no spaces in between. Im sure this can be done by using coding instead bcoz i dnt really like the bindingnavagotor, after all this s'pose to be a Point of sale system, so i dnt think the navigator is needed.

Thanks

Infact (pardon the double post) in your sqlquery is there a space between @ and the word productID?

if so, this is wrong it should be one word as follows:

@PRODUCTID
 
Hi actually i get this error when doing the sql statement in the wizard

"generated seletc statement
error in WHERE clause near '@'
unable to parse query text"
 
Hi no there's no spaces in between. Im sure this can be done by using coding instead bcoz i dnt really like the bindingnavagotor, after all this s'pose to be a Point of sale system, so i dnt think the navigator is needed.

Thanks

you dont have to use a bindingnav - it is merely a component that alters the position of a bindingsource. it can be removed from the form if needs be
 
da.SelectCommand = cmd
da.SelectCommand.Parameters.AddWithValue("@ProductID", txtInv.Text)
da.Fill(ds)

DataGridView1.DataSource = ds.Tables(0)


End Sub


Private Sub POSForm3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
da.SelectCommand = cmd
da.SelectCommand.Parameters.AddWithValue("@ProductID", "*")
da.Fill(ds)


DataGridView1.DataSource = ds.Tables(0)
ds.Tables(0).Rows.Clear()
End Sub

Why o why are you doing this addition of parameters in code? THis is all done for you by the IDE. For an example, click the DW2 link in my signature, and follow the walkthrough for "Creating a simple app"

Hopefully it will clear up some things for you..
 
Incidentlaly, you wont succeed in adding multiple items to a datatable, if the tableadapter youre using to fill that datatable has the ClearBeforeFill property set to true..
 
Hi as i mention in my first post i am trying to create a Point of sale system, so i only want the data to be displayed in the datagrid after typing in the productid in the text field and clicking enter. The datagrid has to be empty apart from the columns Price, name and Product id which is there by default.

Hope you can help me solve the problem.



Why o why are you doing this addition of parameters in code? THis is all done for you by the IDE. For an example, click the DW2 link in my signature, and follow the walkthrough for "Creating a simple app"

Hopefully it will clear up some things for you..
 
Hi yeh i checked your right about the space. But when i click next i get this error

VB.NET:
generated select statement
error in WHERE clause near '@'
[IMG]http://www.vbdotnetforums.com/images/misc/progress.gif[/IMG] unable to parse query text [URL="http://www.vbdotnetforums.com/editpost.php?do=editpost&p=58060"][/URL]



sounds like you have a space between @ and productid

VB.NET:
@PRODUCTID - correct
@ PRODUCTID - wrong
(the sql you pasted in earlier has a gap:)
 
Back
Top