473,385 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to update gridview using vb.net and microsoft access?

Hi, i am new to vb.net so i have been facing a lot of problems with my code. Can someone pls check for me where i go wrong..thanks

p.s I'm using visual basic 2005

my code is below

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Server.MapPath("database\db1.mdb")

Dim conn As New OleDbConnection(strConn)
conn.Open()
Dim da As New OleDbDataAdapter
Dim updatecommand As New OleDbCommand("Update Coor_Remark From Table3", conn)
updatecommand.Connection = conn
Dim ds As New DataSet(strConn)
da.Update(ds, "Table3")
GridView1.DataSource = ds.Tables("Coor_Remark")
GridView1.DataBind()

conn.Close()
End Sub
Mar 21 '07 #1
2 2384
hai,
dg is the datagrid used to output database details..........

On page load:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Page.IsPostBack = False Then
binddata()
End If
End Sub

Function (created by us):

Private Sub binddata()
Dim con As New SqlConnection("server=SANISH1; database=master; uid=sa; pwd= ")
con.Open()
Dim da As New SqlDataAdapter("select * from xyz", con)
Dim ds As New DataSet
da.Fill(ds)
dg.DataSource = ds
dg.DataBind()
con.Close()
End Sub

Updation part:

Private Sub update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles insert.Click
Dim con As New SqlConnection("server=xxx; database=master; uid=sa; pwd= ")
con.Open()
Dim strid As String = txtuserid.Text.Trim()
Dim strname As String = txtusername.Text
Dim strpwd As String = txtpwd.Text
Dim cmd As New SqlCommand("update xyz set uname=@uname where userid=@userid", con)
cmd.Parameters.Add("@uname", strname)
cmd.Parameters.Add("@pwd", strpwd)
cmd.ExecuteNonQuery()
Response.Write("Records Updated")
binddata()
con.Close()

End Sub

this is the easy way to start doing VB.NET....
if u hav more doubt.. go to the following link..
http://asp.dotnetheaven.com/howto/doc/adoplus/UpdateDataFromDB.aspx
Mar 21 '07 #2
Hi, thanks for the reply.

However, i still have error in my program. There is some problem with my cmd.Parameters.Add

The error msg is below.....

'Public Function Add(parameterName As String, value As Object) As System.Data.OleDb.OleDbParameter' is obsolete: 'Add(String parameterName, Object value) has been deprecated. Use AddWithValue(String parameterName, Object value). http://go.microsoft.com/fwlink/?linkid=14202'

i also have problem with this line:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles insert.click

the error -------->Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Can someone help, i have no idea what the errors mean.....Thanks
Mar 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael Glass | last post by:
I'm working on an ASP.Net web app using VS2005 and the .Net 2.0 framework, and I have a serious problem with the page I'm currently working on. The page has, among other things, two FormViews and a...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
1
by: Scott F K Hooper | last post by:
VB.NET 2.0 project... I have an Access database with a table that has one primary key. I have used the Add TableAdapter wizard in VS2005 to create my TableAdapter. Next I added an ObjectDataSource...
5
by: Norbert Ruessmann | last post by:
Hello group, I have a business object, which contains Orders. Each Order has a list of OrderItems. Orders are collected in a list List<Order>, OrderItems for each order are of type...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
1
by: gabe | last post by:
How do you call a client side javascript callback method after an update panel has posted back to the server? I have two update panels (A + B) with a gridview in each panel. GridView B has a...
3
by: pvong | last post by:
VB.NET How do you change a gridview from Update mode to normal mode? I'm usually dealing for Formviews and there is a ChangeMode option but I don't see one for Gridviews.
4
by: tim.cavins | last post by:
I have a GridView populated by an ObjectDataSource. I am having issues passing the parameters to the objectdatasource. I have verified that the method is being called but none of the parameters...
5
by: Luqman | last post by:
I added new rows to the GridView with the following code. I am using SqlDataSource and Sql Server 2000 Northwind Database Customers table. Dim sqlarg As New DataSourceSelectArguments Dim dv...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.