Please help in Update---Newbie question

  • Thread starter Thread starter Sajid
  • Start date Start date
S

Sajid

Hello! Experts,

I have the following piece of code in VB.NET that I want to use to
update any records in the database. I would like to use a code as well
as DataGrid to update the records. Please guide me how can I achieve
it. I know there is an Update command to to do this that but since I
am a newbie I don't know how? I'll be really grateful to those who may
help me buy modifying the following code. I am really desperately
looking for your help. I know this will only take a fraction of your
time but it will be a very big help for me. Thanks to all...

------------------------------------------------------------------------
Private odbcAd As New Microsoft.Data.Odbc.OdbcDataAdapter
Private Conn As New Microsoft.Data.Odbc.OdbcConnection
Private ds As New DataSet("AnyTable")

Conn.ConnectionString = "DSN=TestDSN"

Conn.Open()

Dim SQL As String
SQL = "SELECT * FROM AnyTable"

odbcAd = New Microsoft.Data.Odbc.OdbcDataAdapter(SQL, Conn)

ds.Clear()

odbcAd.Fill(ds, "AnyTable")

DataGrid1.SetDataBinding(ds, "AnyTable")

ds.Tables("AnyTable").Rows(1).Item(3) = "Test"
------------------------------------------------------------
 
Hello Sajid -

You need to call the Update method of your DataAdapter. Check out this help
topic:

Updating a Data Source with a Dataset (Visual Basic and Visual C# Concepts)
http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskPerformingUpdates.as
p


hope that helps


Steve Stein
VB Team

This posting is provided "AS IS" with no warranties and confers no rights.

--------------------

Hello Steve,

Thanks a lot for your help. You know I am writing all the code myself
so what that means is that the Data Adapter Wizard has not generated
the Update, Insert, Delete or Select statements. So when I'll call
Update method of Data Adapter then it will throw an exception. Now you
must be wondering that why am I not using the wizard to generate the
code for me. Now the answer is that the Wizard displays this error
message "Could not determine which columns uniquely identify the rows
for "AnyTable", when it tries to generate Update and Delete
statements. And it is right because I am using old FoxPro tables which
do not have any primary key. So could you please help me in this
situation. I'll be really obliged.

cheers

Sajid
 
Sajid,

You can create a command and manually call it's ExecuteNonQuery method to
update the database.

Check out this topic:

Executing Updates or Database Commands using a Data Command (Visual Basic
and Visual C# Concepts)
http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskExecutingUpdatesOrDa
tabaseCommandsUsingDataCommand.asp

You can assign the command as the DataAdapter's update command and use the
dataadapter to execute it. You can do the same for your Delete command as
well.

hope that helps you out...

Steve Stein
VB Team

This posting is provided "AS IS" with no warranties and confers no rights.

--------------------
From: (e-mail address removed) (Sajid)
Newsgroups: microsoft.public.dotnet.languages.vb
Subject: Re: Please help in Update---Newbie question
Date: 6 Feb 2004 02:01:51 -0800
Organization: http://groups.google.com
Lines: 93
Message-ID: <[email protected]>
References: <[email protected]>
NNTP-Posting-Host: 80.255.41.4
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1076061712 8781 127.0.0.1 (6 Feb 2004 10:01:52 GMT)
X-Complaints-To: (e-mail address removed)
NNTP-Posting-Date: Fri, 6 Feb 2004 10:01:52 +0000 (UTC)
Path: cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!news-spur1.maxwell.syr.edu!n
ews.maxwell.syr.edu!postnews1.google.com!not-for-mail
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:179333
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

(e-mail address removed) ("Steven Stein [MSFT]") wrote in message
Hello Sajid -

You need to call the Update method of your DataAdapter. Check out this help
topic:

Updating a Data Source with a Dataset (Visual Basic and Visual C# Concepts)
http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskPerformingUpdates.as
p


hope that helps


Steve Stein
VB Team

This posting is provided "AS IS" with no warranties and confers no rights.

Hello Steve,

Thanks a lot for your help. You know I am writing all the code myself
so what that means is that the Data Adapter Wizard has not generated
the Update, Insert, Delete or Select statements. So when I'll call
Update method of Data Adapter then it will throw an exception. Now you
must be wondering that why am I not using the wizard to generate the
code for me. Now the answer is that the Wizard displays this error
message "Could not determine which columns uniquely identify the rows
for "AnyTable", when it tries to generate Update and Delete
statements. And it is right because I am using old FoxPro tables which
do not have any primary key. So could you please help me in this
situation. I'll be really obliged.

cheers

Sajid
 
Back
Top