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

  • SEARCH
  • Home
  • 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 7714749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:12:33+00:00 2026-06-01T02:12:33+00:00

This is the code for displaying data from database to gridview….If i am doing

  • 0

This is the code for displaying data from database to gridview….If i am doing any changes in GridView and it has to update in database…I dont know how to do it…Can anyone help me….

    Dim DBCONSRT, QRYSTR As String

    Dim strSQL As String

    Dim DBCON, myConn, myCommand, rs As Object

    Dim NoOfRecords As Long
    rs = CreateObject("ADODB.Recordset")
    Const DB_CONNECT_STRING = "Provider=MSDASQL.1;Persist Security Info=False;User ID=cpa5k;Data Source=NP1;DSN=NP1;UID=cpa5k;PASSWORD=pass;SDSN=Default;HST=ibslnpb1.sysplex.homedepot.com;PRT=4101;Initial Catalog=QA1MM;"
    myConn = CreateObject("ADODB.Connection")
    myCommand = CreateObject("ADODB.Command")
    myConn.Open(DB_CONNECT_STRING)
    myCommand.ActiveConnection = myConn
    strSQL = "select * from QA1MM.STRSK_OH FETCH FIRST 10 ROWS ONLY with ur;"
    rs.Open(strSQL, myConn)
    Dim myDA As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
    Dim myDS As DataSet = New DataSet

    myDA.Fill(myDS, rs, "MyTable")
    DataGridView1.DataSource = myDS.Tables(0)
    DataGridView1.Refresh()
    myConn.Close()

I am trying this method.but it is not working

    Dim myDA As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
    Dim myDS As DataSet = New DataSet
    myDA.Fill(myDS, rs, "MyTable")
    ds = DataGridView1.DataSource
    myDA.Update(ds)

I changed like this:

    Dim DBCONSRT, QRYSTR As String
    Dim strSQL As String
    Dim DBCON, myConn, myCommand, rs As Object
    Dim ds As DataSet = New DataSet
    rs = CreateObject("ADODB.Recordset")
    Const DB_CONNECT_STRING = "Provider=MSDASQL.1;Persist Security Info=False;User ID=cpa5k;Data Source=NP1;DSN=NP1;UID=cpa5k;PASSWORD=mexico13;SDSN=Default;HST=ibslnpb1.sysplex.homedepot.com;PRT=4101;Initial Catalog=QA1MM;"
    myConn = CreateObject("ADODB.Connection")
    myCommand = CreateObject("ADODB.Command")
    myConn.Open(DB_CONNECT_STRING)
    myCommand.ActiveConnection = myConn

    Dim myDA As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter
    Dim myDS As DataSet = New DataSet
    Dim dtable As DataTable = New DataTable()
    myDA.UpdateCommand = New SqlClient.SqlCommand("UPDATE QA1MM.STRSK_OH set OH_QTY = 10  WHERE SKU_NBR = 108011", myConn)
    '   myDA.UpdateCommand.Parameters.Add("@OH_QTY", OleDb.OleDbType.VarChar, 15, "OH_QTY")
    '   myDA.UpdateCommand.Parameters.Add("@SKU_NBR", OleDb.OleDbType.VarChar, 15, "SKU_NBR")
    '   myDA.UpdateCommand.Parameters(0).SourceVersion = DataRowVersion.Current
    '   myDA.UpdateCommand.Parameters(1).SourceVersion = DataRowVersion.Current
    dtable = DataGridView1.DataSource
    myDA.Update(dtable)
    myConn.Close()

But it is giving error like “Unable to cast COM object of type ‘System.__ComObject’ to class type ‘System.Data.SqlClient.SqlConnection’. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.”

I changed the connection string like:

Provider=MSDASQL.1;Persist Security Info=False;Data 
Source=NP1;DSN=NP1;SDSN=Default;HST=ibslnpb1.sysplex.homedepot.com;PRT=4101;Integrated 
Security = True;Initial Catalog=QA1MM;

Its not working.The error is “Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.”…..Sorry i dont know how to change…..

  • 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-01T02:12:35+00:00Added an answer on June 1, 2026 at 2:12 am

    You write like follow

    myConn.Open(DB_CONNECT_STRING) 
    myDA.Update(ds.Tables(0))
    myConn.Close() 
    

    EDIT:

    Dont take the datasource of DataGridView1 into a dataset, instead take into a DataTable as follows

                Dim dtable As New DataTable()
                dtable = DataGridView1.DataSource
    

    and update the table with DataAdapter as

    myConn.Open(DB_CONNECT_STRING) 
    myDA.Update(dtable)
    myConn.Close() 
    

    Refer to this link How to write UpdateCommand to OleDBDataAdapter

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

Sidebar

Related Questions

Hi I have been using this code to fetch data from mysql database and
I'm a bit confused about displaying data from a MySQL database. I would like
This code is from Prototype.js . I've looked at probably 20 different tutorials, and
I am having problems displaying images which have been queried from the database. The
I have 2 questions. One is if there is any error in this code.
hi everyone i am fetching some data from a database using php, encoding it
So my software is displaying a flextable (the data is grabbed and displayed from
I am trying to show the data coming from mysql database as a table
I am to displaying rows from a database (SQL SERVER 2005) table in a
I am getting the data from sqlite database and trying to display it in

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.