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
LVL 3
jeshbrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

use

        dgTaskGrid.DataSource = TandADataset.Tables( "TaskTable")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.