[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

gridview select based on a sp

Posted on 2011-02-17
6
Medium Priority
?
375 Views
Last Modified: 2012-05-11
i import a list of customers into a gridview from a spread sheet.
What i want to do is get the user to click on another button then populate a gridview will all the customer details.
Public Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        If FileUpload1.HasFile Then
            Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
            Dim Extension As String = Path.GetExtension(FileUpload1.PostedFile.FileName)

            Dim FolderPath As String = ConfigurationManager.AppSettings("FolderPath")
            Dim FilePath As String = Server.MapPath(FolderPath + FileName)

            FileUpload1.SaveAs(FilePath)
            Import_To_Grid(FilePath, Extension, rbHDR.SelectedItem.Text)
        End If

    End Sub

    Public Sub Import_To_Grid(ByVal FilePath As String, ByVal Extension As String, ByVal isHDR As String)

        Dim conStr As String = ""

        Select Case Extension
            Case ".xls"
                'Excel 97-03 
                conStr = ConfigurationManager.ConnectionStrings("Excel03ConString").ConnectionString()
                Exit Select
            Case ".xlsx"
                'Excel 07 
                conStr = ConfigurationManager.ConnectionStrings("Excel07ConString").ConnectionString()
                Exit Select
        End Select

        conStr = String.Format(conStr, FilePath, isHDR)

        Dim connExcel As New OleDb.OleDbConnection(conStr)
        Dim cmdExcel As New OleDb.OleDbCommand()
        Dim oda As New OleDb.OleDbDataAdapter()

        Dim dt As New DataTable()

        cmdExcel.Connection = connExcel

        'Get the name of First Sheet  
        connExcel.Open()

        Dim dtExcelSchema As DataTable
        dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, Nothing)

        Dim SheetName As String = dtExcelSchema.Rows(0)("TABLE_NAME").ToString()
        connExcel.Close()

        'Read Data from First Sheet 
        connExcel.Open()
        cmdExcel.CommandText = "SELECT * From [" & SheetName & "]"
        oda.SelectCommand = cmdExcel
        oda.Fill(dt)
        connExcel.Close()

        'Bind Data to GridView 
        GridView1.Caption = Path.GetFileName(FilePath)
        GridView1.DataSource = dt
        GridView1.DataBind()

    End Sub

Open in new window

0
Comment
Question by:aneilg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 3

Expert Comment

by:jmro20
ID: 34920703
What column or columns on the gridview will have the value(s) that the sp will be receiving as parameter(s)?
0
 
LVL 3

Expert Comment

by:jmro20
ID: 34921012
Try this:
0
 
LVL 3

Accepted Solution

by:
jmro20 earned 2000 total points
ID: 34921088
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cnn As New SqlConnection("")
        Dim yourCommand As New SqlCommand("yourSP", cnn)
        Dim MySqlDataAdapter As New SqlDataAdapter

        yourCommand.CommandType = CommandType.StoredProcedure

        If cnn.State <> ConnectionState.Open Then cnn.Open()
        Dim param As SqlParameter = New SqlParameter("@parameterName", SqlDbType.Int)

        'If you are using SelectionMode = FullRowSelect
        If DataGridView1.SelectedRows.Count > 0 Then
            param.Value = DataGridView1.SelectedRows(0).Cells("ColumnNameOfTheCustomerId").Value
        Else
            'message - must select customer
        End If

        'If you are using SelectionMode = CellSelect
        If DataGridView1.SelectedCells.Count > 0 Then
            param.Value = DataGridView1.SelectedCells(0).Value
        Else
            'message - must select customer
        End If

        yourCommand.Parameters.Add(param)

        Dim ds As New DataSet

        MySqlDataAdapter = New SqlDataAdapter(yourCommand)

        MySqlDataAdapter.Fill(ds, "Records")

        DataGridView2.DataSource = Nothing
        DataGridView2.DataSource = ds.Tables("Records")

        cnn.Close()

    End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:aneilg
ID: 34924401
thanks i'll give it a go.

an example will be,
abc company
efg company.

Theres customers will be displayed in the gridview, what i then want to do is pass each customer name into a parameter, then display the full address of the customer. either in the same gridview or a new gridview.

I need to display the full list of customers not just one.
0
 
LVL 3

Expert Comment

by:jmro20
ID: 34925297
Do you want to display the address when a user clicks on the customers gridview? or Do you want to get the address of each company after you read the excel file?
0
 

Author Closing Comment

by:aneilg
ID: 35163795
thanks.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question