Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 10th, 2009, 11:08 AM
Authorized User
 
Join Date: Jul 2008
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with an insert code using vb2005 on access database

<%@ page language="vb" runat="server" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<script runat=server>
Sub Page_Load()
If (Not IsPostBack) then
LoadData()
End If
End Sub
Sub LoadData()
dim OurConnection as OleDbConnection
dim OurCommand as OleDbCommand
dim OurDataAdapter as OleDbDataAdapter
dim OurDataSet as New DataSet()
OurConnection = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("./employee.mdb"))
OurConnection.Open()
OurCommand = New OleDbCommand("Select FirstName,LastName from Employees",OurConnection)

OurDataAdapter = New OleDbDataAdapter(OurCommand)
OurDataAdapter.Fill(OurDataSet, "Employees")
OurDataGrid.DataSource=OurDataSet.Tables("Employee s")
UpdateEmployeeID.DataSource=OurDataSet.Tables("Emp loyees")
DeleteEmployeeID.DataSource=OurDataSet.Tables("Emp loyees")
DataBind()

End Sub
Sub UpdateSetup(sender As Object, e As System.EventArgs)
UpdateSelect.Visible="False"
UpdateTextBoxes.Visible="True"
dim SelectedID as String = UpdateEmployeeID.SelectedItem.Value
UpdateButton.CommandArgument = SelectedID
dim OurConnection as OleDbConnection
OurConnection = New OleDbConnection("Server=server;uid=newriders;pwd=p assword;database=Northwind")
OurConnection.Open()
dim OurCommand as OleDbCommand
dim OurDataReader2 as OleDbDataReader
OurCommand = New OleDbCommand("Select FirstName, LastName From Employees Where EmployeeID = " + SelectedID ,OurConnection)
OurDataReader2 = OurCommand.ExecuteReader()
OurDataReader2.Read()
UpdateFirstName.Visible="True"
UpdateLastName.Visible="True"
UpdateFirstName.Text = OurDataReader2("FirstName")
UpdateLastName.Text = OurDataReader2("LastName")
OurConnection.Close()
OurDataReader2.Close()
LoadData()
End Sub
Sub UpdateReset(sender As Object, e As System.EventArgs)
UpdateSelect.Visible="True"
UpdateTextBoxes.Visible="False"
LoadData()
End Sub
Sub InsertCommand(sender As Object, e As System.EventArgs)
dim OurConnection as OleDbConnection
OurConnection = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("./employee.mdb"))
dim OurCommand as OleDbCommand
OurCommand = New OleDbCommand("Insert Into Employees (FirstName, LastName) Values (@FirstName, @LastName)" ,OurConnection)
OurCommand.Parameters.Add("@FirstName", oledbType.Varchar, 10).Value = InsertFirstName.Text
OurCommand.Parameters.Add("@LastName", oledbType.Varchar, 20).Value = InsertLastName.Text
OurConnection.Open()
OurCommand.ExecuteNonQuery()
OurConnection.Close()
LoadData()
End Sub
Sub UpdateCommand(sender As Object, e As System.Web.UI.WebControls.CommandEventArgs)
dim OurConnection as OleDbConnection
dim OurCommand as OleDbCommand
dim EmployeeID as String = e.CommandArgument
OurConnection = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("./employee.mdb"))
OurCommand = New OleDbCommand("Update Employees Set Firstname = @FirstName,LastName = @LastName Where EmployeeID = " +EmployeeID, OurConnection)
OurCommand.Parameters.Add("@FirstName", oledbType.Varchar, 10).Value =UpdateFirstName.Text
OurCommand.Parameters.Add("@LastName", oledbType.Varchar, 20).Value =UpdateLastName.Text
OurConnection.Open()
OurCommand.ExecuteNonQuery()
OurConnection.Close()
LoadData()
End Sub
Sub DeleteCommand(sender As Object, e As System.EventArgs)
dim OurConnection as oledbConnection
dim SelectedID as String = DeleteEmployeeID.SelectedItem.Value
dim OurCommand as oledbCommand
OurConnection = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("./employee.mdb"))
OurCommand = New oledbCommand("Delete Employees Where EmployeeID = " + SelectedID, OurConnection)
OurConnection.Open()
OurCommand.ExecuteNonQuery()
OurConnection.Close()
LoadData()
End Sub
</script>
<html>
<head>
<title>ADO oledbCommand -Insert,Update,Delete</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form runat="server">
<table border="0" cellpadding="0" cellspacing="20">
<tr><td>
<ASP:DataGrid
id="OurDataGrid"
EnableViewState="false"
BorderWidth="1"
BorderColor="#000000"
CellPadding="3"
CellSpacing="0"
Font-Name="Verdana"
HeaderStyle-BackColor="#AAAAAA"
ItemStyle-BackColor="#EEEEEE"
runat="server" />
</td><td>
<h4>Insert</h4>
First Name: <asp:TextBox id="InsertFirstName" runat="server" /><br>
Last Name: <asp:TextBox id="InsertLastName" runat="server" />
<asp:button runat="server" OnClick="InsertCommand" text="Submit" /><br><br>
<hr style="height:1px">
<h4>Update</h4>
<asp:Panel id="UpdateSelect" runat="server" >
EmployeeID:
<asp:DropDownList
id="UpdateEmployeeID"
DataTextField="EmployeeID"
DataValueField="EmployeeID"
runat="server" />
<asp:button runat="server" text="Select" OnClick="UpdateSetup" />
</asp:Panel>
<asp:Panel id="UpdateTextBoxes" Visible="false" runat="server" >
First Name: <asp:TextBox id="UpdateFirstName" runat="server" />
<asp:button
id="UpdateButton"
onCommand="UpdateCommand"
runat="server"
text="Update" /><br>
Last Name: <asp:TextBox id="UpdateLastName" runat="server" />
<asp:button id="CancelUpdateButton" runat="server" onClick="UpdateReset" text="Select
Other" />
</asp:Panel><br>
<hr style="height:1px">
<h4>Delete</h4>
EmployeeID:
<asp:DropDownList
id="DeleteEmployeeID"
DataTextField="EmployeeID"
DataValueField="EmployeeID"
runat="server" />
<asp:button runat="server" text="Delete" onClick="DeleteCommand" />
</td></tr>
</table>
</form>
</body>
</html>

returns d ff errors
Operation must use an updateable query.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Operation must use an updateable query.
Source Error:

Line 70: OurCommand.Parameters.Add("@LastName", oledbType.Varchar, 20).Value = InsertLastName.Text
Line 71: OurConnection.Open()
Line 72: OurCommand.ExecuteNonQuery()
Line 73: OurConnection.Close()
Line 74:

Source File: c:\inetpub\wwwroot\sat.aspx Line: 72
Stack Trace:
what should i do
__________________
busteronline
 
Old August 10th, 2009, 12:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Strings should be surrounded by ' (simple quotes)... That's probably the error...
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old August 11th, 2009, 01:41 PM
Authorized User
 
Join Date: Jul 2008
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Operation must use an updateable query. is d error message even when i tried it with all the quotes in the right place, i guess the problem is access and vb2005,somebody should help out
__________________
busteronline
 
Old August 11th, 2009, 01:44 PM
Authorized User
 
Join Date: Jul 2008
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Operation must use an updateable query. is d error message, i guess its betwn accesss and vb2005
thanks
__________________
busteronline
 
Old August 11th, 2009, 02:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

there is no problem between access and vb 2005. Do you have right to write on the mdb??? Do the query work inside access???
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old August 12th, 2009, 09:53 AM
Authorized User
 
Join Date: Jul 2008
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how do i get the access or change d access talked about,thanks
__________________
busteronline
 
Old August 12th, 2009, 10:06 AM
Authorized User
 
Join Date: Jul 2008
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

pls how do i go about changing this right/or how do i kn ow d righrts i have on the database,thanks
__________________
busteronline





Similar Threads
Thread Thread Starter Forum Replies Last Post
INSERT into Access Database from VBA for Excel zuerlein Excel VBA 0 June 3rd, 2007 01:51 AM
Insert row into MS-ACCESS database ITladybug ADO.NET 1 January 28th, 2006 07:57 AM
INSERT info into a Access database for display sideshow245 Classic ASP Databases 2 January 7th, 2004 04:25 PM
INSERT string into a Microsoft Access Database gsolis Classic ASP Databases 1 December 31st, 2003 05:31 PM
Database access from java, INSERT query problem nitusincog BOOK: Beginning Java 2 1 July 21st, 2003 10:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.