Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8581007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:56:52+00:00 2026-06-11T20:56:52+00:00

I get a catch exp as Exception Error in which says, data source is

  • 0

I get a catch exp as Exception Error in which says, data source is an invalid type, it must either be of the type IListSource, IEnumerable or IDataSource.

This error comes when I try to add a new record to a database through a gridview, so I get the data from database nicely into this gridview, therefore I do not understand that I get a catch exp as exception when the database is not unavailable.
The @thesli_number OleDbType.VarChar Value = thenumber is type of number in the db.

 'Add new record to DB
Protected Sub AddNewTask(ByVal sender As Object, ByVal e As EventArgs)
    Dim thecat As String = DirectCast(GridView1.FooterRow.FindControl("txttestcat"), TextBox).Text
    Dim theinfo As String = DirectCast(GridView1.FooterRow.FindControl("txttestinfo"), TextBox).Text
    Dim thenumber As String = DirectCast(GridView1.FooterRow.FindControl("txttestnumber"), TextBox).Text

    Dim strSQL As String = ""
    strSQL = "" & _
    "INSERT INTO [TableTest] " & _
    "([test_cat], [test_info], [test_number])" & _
    "VALUES (@thesli_cat, @thesli_info, @thesli_number)"

    Using conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("MyConnStr").ConnectionString)
        Try
            conn.Open()
            Dim cmd As New OleDbCommand(strSQL, conn)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.Add("@thesli_cat", OleDbType.VarChar).Value = thecat
            cmd.Parameters.Add("@thesli_info", OleDbType.VarChar).Value = theinfo
            cmd.Parameters.Add("@thesli_number", OleDbType.VarChar).Value = thenumber
            GridView1.DataSource = cmd
            GridView1.DataBind()
            'MsgBox("Row(s) Added !! ")
        Catch exp As OleDbException
            If True Then
                MsgBox("Error trying to add current record. " & vbCrLf & "Error: " & exp.Message & "Database Error", MsgBoxStyle.OkOnly, MsgBoxStyle.Critical)
            End If
        Catch exp As Exception
            If True Then
                MsgBox("Error the Database can be unavailable atm. " & vbCrLf & "Error: " & exp.Message & "Database Error", MsgBoxStyle.OkOnly, MsgBoxStyle.Information)
            End If
        End Try
    End Using
End Sub

EDIT…………….EDIT……………..EDIT……………….EDIT

Ok i can now add data to the gridview, i can delete a record and i can add a new record.
But i cant get the update event to work, can u see whats wrong in this new code !?

    'Update record
Protected Sub UpdateTask(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    Dim theid = Convert.ToInt32(DirectCast(GridView1.FooterRow.FindControl("lbltestid"), Label).Text)
    Dim thecat As String = DirectCast(GridView1.FooterRow.FindControl("lbltestcat"), Label).Text
    Dim theinfo As String = DirectCast(GridView1.FooterRow.FindControl("lbltestinfo"), Label).Text
    Dim thenumber As String = DirectCast(GridView1.FooterRow.FindControl("lbltestnumber"), Label).Text

    Dim strSQL As String = ""
    strSQL = "" & _
    "UPDATE [TableTest] " & _
    "SET [test_cat] = @thesli_cat, [test_info] = @thesli_info, [test_number] = @thesli_number " & _
    "WHERE [test_id] = @thesli_id"

    Using conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("MyConnStr").ConnectionString)
        Try
            conn.Open()
            Dim cmd As New OleDbCommand(strSQL, conn)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.Add("@thesli_id", OleDbType.Integer).Value = theid
            cmd.Parameters.Add("@thesli_cat", OleDbType.VarChar).Value = thecat
            cmd.Parameters.Add("@thesli_info", OleDbType.VarChar).Value = theinfo
            cmd.Parameters.Add("@thesli_number", OleDbType.Integer).Value = thenumber
            cmd.ExecuteNonQuery()
            'MsgBox("Row(s) Updated !! ")
            GridView1.EditIndex = -1
            GetRecords()
        Catch exp As OleDbException
            If True Then
                MsgBox("Error trying to add current record. " & vbCrLf & "Error: " & exp.Message & "Database Error", MsgBoxStyle.OkOnly, MsgBoxStyle.Critical)
            End If
        Catch exp As Exception
            If True Then
                MsgBox("Error the Database can be unavailable atm. " & vbCrLf & "Error: " & exp.Message & "Database Error", MsgBoxStyle.OkOnly, MsgBoxStyle.Information)
            End If
        End Try
    End Using
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:56:53+00:00Added an answer on June 11, 2026 at 8:56 pm

    If the answer to your original question was answered in my comment above (posted below here in quotes), then you should mark this question as answered, then post an entirely new question so you get more accurate responses. This question no longer applies to your actual problem.

    My answer which, in your comment, solved your original question:

    That example (referring to the link in your comment above) does not directly assign an
    OleDbCommand to the DataSource, because it
    can’t. If you look at the example the author passes the cmd variable
    to the GetData function GetData(cmd), which more than likely executes
    the stored procedure and returns a DataSource supported type (e.g.
    IListSource, IEnumerable or IDataSource).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have handling the exception in my code as below, but still get error
I cannot seem to get my try/catch to work correctly. When you implement a
I put lock on a few lines which are supposed to get cookie files
I have the following Java code working with XPath to get data from XML
I have tried everything but it seems that you cannot get a catch all
Hi all i've got the following code which will go off and get all
I want to create a wordpress plugin that can catch POST/GET requests to a
I have a C++ library which I'm trying to get running on Mac OS
If I am using a try/catch/finally block where and how should I initialize variables?
Hi I would like to wrap the following comma separated data: -X, run, abs,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.