Click here to Skip to main content
15,899,026 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Where to update datagrid cells Pin
Suresh Suthar27-Jul-11 20:40
professionalSuresh Suthar27-Jul-11 20:40 
GeneralRe: Where to update datagrid cells Pin
LCARS x3211-Aug-11 6:24
LCARS x3211-Aug-11 6:24 
QuestionGridView appears to have no data when trying to sort it Pin
dannyboi8627-Jul-11 1:12
dannyboi8627-Jul-11 1:12 
AnswerRe: GridView appears to have no data when trying to sort it Pin
Shameel27-Jul-11 2:24
professionalShameel27-Jul-11 2:24 
GeneralDataAdapter / Datatable Pin
David Mujica27-Jul-11 2:49
David Mujica27-Jul-11 2:49 
GeneralRe: DataAdapter / Datatable Pin
dannyboi8627-Jul-11 3:29
dannyboi8627-Jul-11 3:29 
GeneralRe: DataAdapter / Datatable Pin
David Mujica27-Jul-11 10:49
David Mujica27-Jul-11 10:49 
GeneralRe: DataAdapter / Datatable Pin
dannyboi8627-Jul-11 22:29
dannyboi8627-Jul-11 22:29 
Hello David,

I have made the changes you suggested, but am still getting the same error:

Here is the code now:

<script runat="server" >          
        
        Public Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
            
            Dim sqlConn As New SqlConnection
            Dim sqlCmd As New SqlClient.SqlCommand
            'Dim sqlReader As SqlDataReader
            Dim sqlAdapter As New SqlDataAdapter
            Dim sqlDataTable As New DataTable
                        
            'If no values are supplied in the textbox, throw an error message.
            If TextBox2.Text = "" Then
                MsgBox("A centre code needs to be provided...")
            End If
            
            If TextBox2.Text <> "" Then
            
                'Telling the system the location of the database.
                sqlConn.ConnectionString = "server=ServerName;Initial Catalog=dbName;Trusted_Connection=yes"

                'Here we are opening the connection to the database.
                sqlConn.Open()
                
                'This is to say that sqlCmd is a stored procedure.
                sqlCmd.CommandType = System.Data.CommandType.StoredProcedure
                        
                'This is creating the command to execute the stored procedure based on the information given in the connection string.
                sqlCmd = sqlConn.CreateCommand

                'The command is triggered to execute the stored procedure which grabs all information for the specific centre.
                sqlCmd.CommandText = "exec ProcedureName'" & TextBox2.Text & "' "
                
                'This will read the rows in the database.
                'sqlReader = sqlCmd.ExecuteReader()
                
                'If there are rows of data that match are criteria
                'If (sqlReader.HasRows) Then

                    'The rows of data are grabbed for the specific centre from the database using the data reader.
                'GridView2.DataSource = sqlReader
                'GridView2.DataBind()
                    
                    sqlAdapter = New SqlDataAdapter(sqlCmd)
                    sqlAdapter.Fill(sqlDataTable)
                    
                GridView2.DataSource = sqlDataTable
                GridView2.DataBind()
                    
                Else
                    MsgBox("The centre code provided does not exist...")
                'End If
                
                'This is closing the connection to the database once we have finished with it.
                'sqlConn.Close()
                
              
            End If
        End Sub
                           
        
        


        Public Sub gvSorting_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
            
            Dim dt = TryCast(Session("TaskTable"), DataTable)
            Dim dtSortView As New DataTable
            dtSortView = GridView2.DataSource
            
            If dtSortView Is Nothing Then
                Dim dvSortedView As New DataView(dtSortView)

                dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection)
                
                GridView2.DataSource = dvSortedView
                GridView2.DataBind()
            End If
        End Sub
                 
        Public Function getSortDirectionString(ByVal SortDirection As SortDirection) As String

            Dim newSortDirection As String = String.Empty
        
            If (SortDirection = SortDirection.Ascending) Then
                newSortDirection = "ASC"
            Else
                newSortDirection = "DESC"
                'Return newSortDirection
            End If

            Return newSortDirection

        End Function
        
        
        </script>


Any ideas at all?

Is there code still in there that needs to be taken out?

Or have I missed a bit of code?

Thanks for your help,

Dan
GeneralRe: DataAdapter / Datatable Pin
Shameel28-Jul-11 3:16
professionalShameel28-Jul-11 3:16 
GeneralRe: DataAdapter / Datatable Pin
David Mujica28-Jul-11 3:20
David Mujica28-Jul-11 3:20 
GeneralRe: DataAdapter / Datatable Pin
dannyboi8628-Jul-11 4:59
dannyboi8628-Jul-11 4:59 
GeneralRe: DataAdapter / Datatable Pin
David Mujica28-Jul-11 9:59
David Mujica28-Jul-11 9:59 
GeneralRe: DataAdapter / Datatable Pin
dannyboi8628-Jul-11 22:34
dannyboi8628-Jul-11 22:34 
GeneralRe: DataAdapter / Datatable Pin
David Mujica29-Jul-11 3:12
David Mujica29-Jul-11 3:12 
GeneralRe: DataAdapter / Datatable Pin
dannyboi8629-Jul-11 5:58
dannyboi8629-Jul-11 5:58 
GeneralRe: DataAdapter / Datatable Pin
David Mujica1-Aug-11 10:50
David Mujica1-Aug-11 10:50 
GeneralRe: GridView appears to have no data when trying to sort it Pin
dannyboi8627-Jul-11 3:45
dannyboi8627-Jul-11 3:45 
GeneralRe: GridView appears to have no data when trying to sort it Pin
Shameel27-Jul-11 5:23
professionalShameel27-Jul-11 5:23 
QuestionSearch and delete files Pin
hendrikbez26-Jul-11 22:29
hendrikbez26-Jul-11 22:29 
AnswerRe: Search and delete files Pin
Andy_L_J26-Jul-11 23:09
Andy_L_J26-Jul-11 23:09 
AnswerRe: Search and delete files Pin
Dave Kreskowiak27-Jul-11 1:27
mveDave Kreskowiak27-Jul-11 1:27 
AnswerRe: Search and delete files Pin
Carmelo La Monica27-Jul-11 2:14
professionalCarmelo La Monica27-Jul-11 2:14 
GeneralRe: Search and delete files Pin
hendrikbez27-Jul-11 19:49
hendrikbez27-Jul-11 19:49 
GeneralRe: Search and delete files Pin
Thomas Krojer28-Jul-11 21:27
Thomas Krojer28-Jul-11 21:27 
GeneralRe: Search and delete files Pin
MicroVirus9-Aug-11 13:54
MicroVirus9-Aug-11 13:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.