none
Copy a data row from sql datagrid to excel name range RRS feed

  • Question

  • What I'm trying to do is double click a row in a data grid and  insert that row into name ranged cells on my worksheet. I've searched the forums and can't find any post about this. Using VSTO and Excel 2010
    Sunday, April 28, 2013 11:49 AM

Answers

  • Hi GBM64,

    Thank you for your reply.

    Based on your description, I think you'll want to see How To : Create SQL Server Management Studio Addin.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 30, 2013 12:32 PM
    Moderator
  • I found this snippet that works for me.
    Dim row As NorthwindDataSet.CustomersRow
            row = CType(CType(Me.CustomersBindingSource.Current, DataRowView).Row, NorthwindDataSet.CustomersRow)
    here is what I used to get the current row to sheet1.
     
    Dim row As CustomerSelectionDataSet.CustomersRow
            row = CType(CType(Me.CustomersBindingSource1.Current, DataRowView).Row, CustomerSelectionDataSet.CustomersRow)
            Dim Message As String = "You Cannot Select a Blank Row"
            
    
            Try
                Globals.Sheet1.GBMWhoId.Value2 = row.CustomerID
                Globals.Sheet1.GBMWhoCompany.Value2 = row.CompanyName
                Globals.Sheet1.GBMWhoFirstName.Value2 = row.FirstName
                Globals.Sheet1.GBMWhoLastName.Value2 = row.LastName
                Globals.Sheet1.GBMWhoAddress.Value2 = row.Address
                Globals.Sheet1.GBMWhoCityStZip.Value2 = (row.CityState & "," & " " & row.PostalZipCode)
                Globals.Sheet1.GBMWhoPhone.Value2 = row.Phone
                Globals.Sheet1.GBMWhoEMail.Value2 = row.EMailAddress
    
                Me.Close()
            Catch ex As Exception
                MsgBox(Message & vbCrLf & ex.ToString)
            End Try

    • Marked as answer by GBM64 Saturday, May 25, 2013 12:01 PM
    • Edited by GBM64 Saturday, May 25, 2013 12:08 PM
    Saturday, May 25, 2013 12:01 PM

All replies

  • Hi GBM64,

    Thank you for posting in the MSDN Forum.

    Could you please show me the current code you have? By "datagrid" do you mean DataGrid control in System.Windows.Controls?

    I look forward to your reply.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 29, 2013 6:33 AM
    Moderator
  • Hi Quist Zhang

    I do not have any code, I'm new to this. Sorry, by datagrid What I actually  meant was  Data Table from SQL Server. I appreciate any help you can give me on this.

    Monday, April 29, 2013 11:52 AM
  • Hi GBM64,

    Thank you for your reply.

    Based on your description, I think you'll want to see How To : Create SQL Server Management Studio Addin.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 30, 2013 12:32 PM
    Moderator
  • Thanks I will give it a try.
    Wednesday, May 1, 2013 12:10 AM
  • I found this snippet that works for me.
    Dim row As NorthwindDataSet.CustomersRow
            row = CType(CType(Me.CustomersBindingSource.Current, DataRowView).Row, NorthwindDataSet.CustomersRow)
    here is what I used to get the current row to sheet1.
     
    Dim row As CustomerSelectionDataSet.CustomersRow
            row = CType(CType(Me.CustomersBindingSource1.Current, DataRowView).Row, CustomerSelectionDataSet.CustomersRow)
            Dim Message As String = "You Cannot Select a Blank Row"
            
    
            Try
                Globals.Sheet1.GBMWhoId.Value2 = row.CustomerID
                Globals.Sheet1.GBMWhoCompany.Value2 = row.CompanyName
                Globals.Sheet1.GBMWhoFirstName.Value2 = row.FirstName
                Globals.Sheet1.GBMWhoLastName.Value2 = row.LastName
                Globals.Sheet1.GBMWhoAddress.Value2 = row.Address
                Globals.Sheet1.GBMWhoCityStZip.Value2 = (row.CityState & "," & " " & row.PostalZipCode)
                Globals.Sheet1.GBMWhoPhone.Value2 = row.Phone
                Globals.Sheet1.GBMWhoEMail.Value2 = row.EMailAddress
    
                Me.Close()
            Catch ex As Exception
                MsgBox(Message & vbCrLf & ex.ToString)
            End Try

    • Marked as answer by GBM64 Saturday, May 25, 2013 12:01 PM
    • Edited by GBM64 Saturday, May 25, 2013 12:08 PM
    Saturday, May 25, 2013 12:01 PM