• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

Problem filling table.

Hello Experts,

I have been trying to connect to a SQL Server DB.  I used Server Explorer to set up the connection and the data adapter. I set up the data set through code.  When i try to fill the table the program fails. Anything can help.

Heres some code to get started:

        Dim strSQL As SqlCommand = TandAConnection.CreateCommand()
        strSQL.CommandText = "Select * from TandATask"
        TandAAdapter.SelectCommand = strSQL

        setupTables()

        Try
            TandAAdapter.Fill(TandADataset, "TaskTable")
        Catch ex As Exception
            MsgBox(ex)
        End Try

        TaskGridBinding = New Binding("Data Source", TandADataset, "TaskTable")
        dgTaskGrid.DataBindings.Add(TaskGridBinding)

What is wrong here?

Thank you,

Jeshbr
0
jeshbr
Asked:
jeshbr
  • 2
2 Solutions
 
iboutchkineCommented:
instead of
  TaskGridBinding = New Binding("Data Source", TandADataset, "TaskTable")
        dgTaskGrid.DataBindings.Add(TaskGridBinding)

use

        dgTaskGrid.DataSource = TandADataset.Tables( "TaskTable")
0
 
RacinRanCommented:
Try setting strSQL.CommandType = CommandType.Text --  this tells the command it's a plain text sql statement as opposed to a stored procedure.

ex.

        Dim strSQL As new SqlCommand("Select * from TandATask")
        strSQL.CommandType = CommandType.Text
        TandAAdapter.SelectCommand = strSQL



Racin
0
 
jeshbrAuthor Commented:
I have been able to work around the problem but I would like to be able to fix it.

My work around was using a DataReader like this:

My data columns are defined like this:

        TaskTableCol = New DataColumn
        TaskTableCol.DataType = System.Type.GetType("System.Decimal")
        TaskTableCol.ReadOnly = True
        TaskTableCol.Unique = True
        TaskTableCol.ColumnName = "TaskID"
        TaskTable.Columns.Add(TaskTableCol)

This is the method code:
   
        Dim strSQL As String
        strSQL = "Select * from TandATask"
        Dim SelectStatement As SqlCommand
        SelectStatement = New SqlCommand(strSQL, TandAConnection)
        SelectStatement.CommandType = CommandType.Text ' Thanks RacinRan for this.
        TandAConnection.Open()

        Dim tempReader As SqlDataReader
        tempReader = SelectStatement.ExecuteReader()

        Do While tempReader.Read.Equals(True)
            TaskTableRow = TaskTable.NewRow
            TaskTableRow("TaskID") = tempReader(0)
            TaskTableRow("EmpID") = tempReader(1)
            TaskTableRow("TaskNumber") = tempReader(2)
            TaskTableRow("Description") = tempReader(3)
            TaskTableRow("Description2") = tempReader(4)
            TaskTableRow("Priority") = tempReader(5)
            TaskTableRow("DueDate") = tempReader(6)
            TaskTableRow("CompleteDate") = tempReader(7)
            TaskTableRow("Complete") = tempReader(8)
            TaskTableRow("Dispatched") = tempReader(9)
            TaskTableRow("Custom") = tempReader(10)
            TaskTableRow("CustomID") = tempReader(11)
            TaskTableRow("Reminder") = tempReader(12)
            TaskTable.Rows.Add(TaskTableRow)
        Loop

        dgTaskGrid.DataSource = TandADataset.Tables("TaskTable") 'Thanks iboutchkine for this little snippet

If I use this:
       
        TandAAdapter.SelectCommand = SelectStatement
        TandAAdapter.Fill(TandADataset, "TaskTable")

I get this error:
        An unhandled exception of type 'System.ArgumentException' occurred in microsoft.visualbasic.dll
        Additional information: Argument 'Prompt' cannot be converted to type 'String'.

Im new to this .net stuff.  I think im getting the hang of it though.
Any suggestions you have are greatly appreciated.
0
 
jeshbrAuthor Commented:
Sorry guys the problem has been solved.

This code:
        Try
            TandAAdapter.Fill(TandADataset, "TaskTable")
        Catch ex As Exception
            MsgBox(ex)
        End Try
 
Was generating this error:
        An unhandled exception of type 'System.ArgumentException' occurred in microsoft.visualbasic.dll
        Additional information: Argument 'Prompt' cannot be converted to type 'String'.

Which led me to look at the wrong things.

It should be:
        Try
            TandAAdapter.Fill(TandADataset, "TaskTable")
        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try

Which gave me the correct error and I was able to figure out the rest on my own.

I have posted many questions now that have been results of stupid mistakes.
Sorry for wasting peoples time.

I would like to thank iboutchkine and RacinRan for the suggestions.
I have used them.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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