[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 597
  • Last Modified:

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
0
demoniumz
Asked:
demoniumz
  • 26
  • 15
1 Solution
 
jpaulinoCommented:
Does the datagridview are bound to something ?
0
 
demoniumzAuthor Commented:
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
0
 
demoniumzAuthor Commented:
Jpaulino can u help?

0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
demoniumzAuthor Commented:
hello anyone to help
0
 
jpaulinoCommented:
Sorry, let my try to look at this later.
0
 
demoniumzAuthor Commented:
ok
0
 
demoniumzAuthor Commented:
ok i wait thnks for help
0
 
jpaulinoCommented:
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
0
 
demoniumzAuthor Commented:
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
0
 
demoniumzAuthor Commented:
so j paulino
0
 
demoniumzAuthor Commented:
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




0
 
jpaulinoCommented:
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 ?
 
0
 
jpaulinoCommented:
0
 
demoniumzAuthor Commented:
what about the text boxes
0
 
demoniumzAuthor Commented:
JPAULINO what code  you need to provide you in order to  help
0
 
demoniumzAuthor Commented:
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

0
 
jpaulinoCommented:
You want to fill the textboxes with the information from the selected item ?
Two very easy examples that I already posted:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23748735.html 
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23750187.html 
Sorry man ... i'm a little busy in this days but I will try to help you more.
0
 
jpaulinoCommented:
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.
 
0
 
demoniumzAuthor Commented:
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
0
 
jpaulinoCommented:
demoniumz,
You have to change somethings and not just copy/paste.
Can you upload what you have ? (the project)
0
 
demoniumzAuthor Commented:
where to  upload it?
0
 
demoniumzAuthor Commented:
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
0
 
jpaulinoCommented:
Ok, now explain what's the problem, now that i can see the foms/code ?
0
 
demoniumzAuthor Commented:
ok  here explain  
untitled.PNG
0
 
jpaulinoCommented:
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

0
 
demoniumzAuthor Commented:
ok you understand what i want to do?
0
 
jpaulinoCommented:
Opps, wrong version
       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)

Open in new window

0
 
demoniumzAuthor Commented:
where i must add these?
0
 
jpaulinoCommented:
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

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 26
  • 15
Tackle projects and never again get stuck behind a technical roadblock.
Join Now