Link to home
Start Free TrialLog in
Avatar of demoniumz
demoniumz

asked on

datagrid view insert data

hi i have 1 combobox  and three textbox i want these fiels to insert it in a datagrid view.HOw i can ihser data on it.I am using vb 2005 linked frommms acess 2003
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Does the datagridview are bound to something ?
Avatar of demoniumz
demoniumz

ASKER

the datagrid is bound to product table but is easy to unbound it.The all problem i have 1 combobox 3 textboxes
i have  1 datagrid view  and need to enter the information from the combobox and the 3 textboxes in to the datagrid view.The second small problem that related to datagrid view is one of the textbox called quantity  because the data of the combobox and the textbox is bounded to products table and for each product the quantity is very high lets say 50 maybe i need to edit 200 this thing is change the data in  the table.what i count do?Add another quantity field maybe OrderQuantity or is any solution for these

sorry if i tired you  but i am new to vb 2005

Thns
Jpaulino can u help?

hello anyone to help
Sorry, let my try to look at this later.
ok
ok i wait thnks for help
i have  1 datagrid view  and need to enter the information from the combobox and the 3 textboxes in to the datagrid view.
To enter where ? In the database ?

The second small problem that related to datagrid view is one of the textbox called quantity  because the data of the combobox and the textbox is bounded to products table and for each product the quantity is very high lets say 50 maybe i need to edit 200 this thing is change the data in  the table.what i count do?Add another quantity field maybe OrderQuantity or is any solution for these
Don't understand this ... what's the problem of change the value
yes to enter it save it in database.3 textboxes one combobox to add to  datagrdi view with a button.The datagr\id view is bound but easy unbound
so j paulino
The all problem is i have a button a datagrid view related to a table  3 text boxes and one combobox.What i want pass the data from the text boxes and from the combobox to the datagrid row.Using the button.

What is the dificulty to these problem and no one help

Using vb 2005 linked from ms access 2003 and using bindin navigator




If you have a bound datagridview, you just need to add an extra combocolumn. When you change that column, you can see in here how to detect the combobox selection change http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23805212.html, you just have to update the cell you need in the same row.
It's not easy to do, it's difficult do explain it all without to have code from you side or an example.
Can you upload an example ?
 
what about the text boxes
JPAULINO what code  you need to provide you in order to  help
hello  i have  find the code from an aplication  but is chaotic  for me  is using what i want a button a datrid view and textboxes can  someone  help me to   make it work/

Using ms access 2003  with vb 2005
Table orderdetails the datagrid is bount to orderdetails
tnks i provide more info if needed


Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        ' write data into disk
        Dim cmd As New OleDbCommand()
        Dim trans As OleDbTransaction
 
        Try
            trans = con.BeginTransaction
            cmd.CommandText = "insert into order_master(orderno,orderdate,orderstatus,custno,ordervalue,requireddate) values(?,sysdate,'rcvd',?,?,?)"
            cmd.Connection = con
            cmd.Transaction = trans
            cmd.Parameters.Add("orderno", OleDbType.Integer).Value = txtOrdno.Text
            cmd.Parameters.Add("custno", OleDbType.Integer).Value = txtCustno.Text
            cmd.Parameters.Add("ordervalue", OleDbType.Integer).Value = txtOrderValue.Text
            cmd.Parameters.Add("orderdate", OleDbType.VarChar, 10).Value = dtpRequiredDate.Text
 
            cmd.ExecuteNonQuery()
            cmd.Parameters.Clear()
            cmd.CommandText = "insert into order_details  values (?,?,?,?)"
            cmd.Parameters.Add("orderno", OleDbType.Integer).Value = txtOrdno.Text
            cmd.Parameters.Add("mcode", OleDbType.VarChar, 20)
            cmd.Parameters.Add("qty", OleDbType.Integer)
            cmd.Parameters.Add("value", OleDbType.Integer)
 
            Dim row As DataRow
            For Each row In itemstable.Rows
                cmd.Parameters(1).Value = row.Item("itemcode").ToString().Split(",")(0)
                cmd.Parameters(2).Value = row.Item("qty")
                cmd.Parameters(3).Value = row.Item("value")
                cmd.ExecuteNonQuery()
            Next
            ' insert into order_tracking table 
            cmd.Parameters.Clear()
            cmd.CommandText = "insert into order_tracking values(?,'rcvd',sysdate)"
            cmd.Parameters.Add("ordno", OleDbType.VarChar, 10).Value = txtOrdno.Text
            cmd.ExecuteNonQuery()
 
            trans.Commit()
            MsgBox("Order Added Successfully")
            ClearOrder()
        Catch ex As Exception
            trans.Rollback()
            MsgBox(ex.Message, , "Error")
        End Try
 
    End Sub

Open in new window

You want to fill the textboxes with the information from the selected item ?
Two very easy examples that I already posted:
https://www.experts-exchange.com/questions/23748735/Binding-DataGridView-to-TextBoxes-Programmatically.html 
https://www.experts-exchange.com/questions/23750187/Questions-regarding-BindingSource.html 
Sorry man ... i'm a little busy in this days but I will try to help you more.
Hey just saw you code snippet ... you don't need all that.
Use the example I have showed to fill and save the datagridview. It's very easy to implement and then you just have to add a datagridviewcomboboxcolumn and when you change it you will update the correct cell in the current row.
 
Private mBS As New BindingSource()
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        ' Creates a demo table      ((TABLE IS ALREADY DO BOUND TO ORDER DETAILS TABLE
        Dim dt As New DataTable()
        dt.Columns.Add("ID", GetType(Integer)).AutoIncrement = True
        dt.Columns.Add("Item", GetType(String))
        dt.Columns.Add("Date", GetType(Date))
 
        ' Adds some rows (ROWS ARE ALLREADY THERE )
        For i As Integer = 0 To 19
            dt.Rows.Add(New Object() {Nothing, "Item " & i, Now.AddDays(i)})
        Next
 
        ' Binds the fields (NOT WORKING  for me ")
        mBS.DataSource = dt
        Me.TextBox1.DataBindings.Add("Text", mBS, "Id", True)
        Me.TextBox2.DataBindings.Add("Text", mBS, "Item", True)
        Me.TextBox3.DataBindings.Add("Text", mBS, "Date", True)
 
        ' Populates the datagridview
        Me.DataGridView1.DataSource = mBS
    End Sub
 
End Class
demoniumz,
You have to change somethings and not just copy/paste.
Can you upload what you have ? (the project)
where to  upload it?
i upload it  few seconds is not all the projectbut two forms that is needed  products and orders:) the Desktop zip  contanins all the data you need thnks;)
http://rapidshare.com/files/223917539/Desktop.rar.html
Ok, now explain what's the problem, now that i can see the foms/code ?
ok  here explain  
untitled.PNG
Remove the combobocolumn and add a new one "textboxcolumn" for the item ProductID
Then use this for button 2:
 

        Dim bsource As BindingSource = Me.OrdersDetailsDataGridView.DataSource
        Dim ds As DataSet = DirectCast(bsource.DataSource, DataSet)
 
        Dim dr As DataRow = ds.Tables("OrdersDetails").NewRow
        dr("OrderID") = 3
        dr("ProductID") = 3
        dr("UnitPrice") = 4
        dr("Quantity") = 4
        ds.Tables("OrdersDetails").Rows.Add(dr)

Open in new window

ok you understand what i want to do?
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
where i must add these?
Where did you asked ?


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim bsource As BindingSource = Me.OrdersDetailsDataGridView.DataSource
        Dim ds As DataSet = DirectCast(bsource.DataSource, DataSet)
 
        Dim dr As DataRow = ds.Tables("OrdersDetails").NewRow
        dr("OrderID") = OrderIDTextBox.Text
        dr("ProductID") = ProductIDComboBox.SelectedValue
        dr("UnitPrice") = UnitPriceTextBox.Text
        dr("Quantity") = QuantityTextBox.Text
        ds.Tables("OrdersDetails").Rows.Add(dr)
    End Sub

Open in new window

you try and is working?
Yep!
Have you done this:
Remove the combobocolumn and add a new one "textboxcolumn" for the item ProductID
can u  upload me back the project i  sent u  with corection i get error
jpaulino can u  upload me back the project i  sent u  with corection i get error
No, I needed to convert to 2008. What error do you have and do you have the datagridview like this:
ee.png
working but i need to edit Product name in  datagrid navigator  that is take from the producsbinding source can u  explain me  how >?
can u explain me  about these
excelent
working but i need to edit Product name in  datagrid navigator  that is take from the producsbinding source can u  explain me  how >?
But you already have the combo with the name.s You need to change ?
the product id in the datagrid view  is display Numbers
not name  that is the problem
anew question is open  jpaulino can  u post there
japaulino i know  that the question is closed by i need help again pls