473,770 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET with VB.NET sql statement for MS ACCESS

hi..
i am using ASP.NET with VB.NET to connect to a MS Access
database...
can someone pls tell me how do i make the sql statement to
insert a new record into the existing table pls??
also how do i filter data?
i mean lets say i wanna filter the NAME field and get all
the names starting with
"Ja"
can someone pls tell how do i write the sql statement to
do that pls?

tks a lot...
Nov 18 '05 #1
5 6702
These really aren't .NET questions, they are "how to write SQL" questions.
Using SQL in .NET with Access/SQL Server isn't really any different then
writing SQL without .NET.

Access itself has a "query designer" which you can use to generate the
proper SQL statement for various tasks. You can then copy that SQL and use
it in .NET.
"josephrtho mas" <ex***********@ yahoo.com.sg> wrote in message
news:02******** *************** *****@phx.gbl.. .
hi..
i am using ASP.NET with VB.NET to connect to a MS Access
database...
can someone pls tell me how do i make the sql statement to
insert a new record into the existing table pls??
also how do i filter data?
i mean lets say i wanna filter the NAME field and get all
the names starting with
"Ja"
can someone pls tell how do i write the sql statement to
do that pls?

tks a lot...

Nov 18 '05 #2
Hola, amigo.

Soy nuevo en este grupo, pero tengo algunos conocimientos que me permitirán
ayudarte.

Primeramente, debes definir cuál tecnología usarás para manipular la base de
datos de MS Access. Puedes usar DAO o ADO, las cuales son las más idóneas
para el uso con este formato de bases de datos: Access. Luego de definir
cuál tecnología usarás (te recomiendo ADO), tendrás que agregarla referencia
al proyecto en el cual lo usaras (yo uso Microsoft Visual Studio .NET), para
esto vas al menú Proyecto->Agregar referencia..., ahí seleccionarás ADODB.
Luego de hacer esto ya tienes la referencia en tu proyecto a la librería
ADODB. procederás a crear las variables para su uso.

Deberás crear una variable de tipo ADODB.Connectio n para manipular una
conexión a una base de datos, luego otra de tipo ADODB.Recordset para
manipular una base de datos. Todo quedaría de la siguiente manera:

Public cnMiConn As new ADODB.Connectio n()
Public rsMiTabla As new ADODB.Recordset ()
Para empezar a manipular la tabla de Access deberás:
1- Establecer las propiedades para la manipulación de la base de datos.
2- Conectarte a la base de datos de Access.
3- Abrir la tabla.
4- Manipular los datos.

Para lograr esto te muestro un fragmento de código donde verás claramente
todo el procedimiento.

Código de ejemplo:
--------------------
Public Class Form1
Inherits System.Windows. Forms.Form

....

Public cnMiConn As New ADODB.Connectio n()
Public rsMiTabla As New ADODB.Recordset ()

Private Sub Form1_Load( ... ) Handles MyBase.Load

'Tipo de bloqueo que usarás para la base de datos
cnMiConn.Mode = ADODB.ConnectMo deEnum.adModeRe adWrite

'Tiempo límite en segundos para efectuar la conexión
cnMiConn.Connec tionTimeout = 15

'Proveedor que usarás para la conexión.
'Existen varios tipos de proveedores. El que se usa para bases de datos de
Access es
'Microsoft.Jet. OLEDB.4.0
cnMiConn.Provid er = "Microsoft.Jet. OLEDB.4.0"

'Cadena de conexión
cnMiConn.Connec tionString = "Password=; User ID=Admin;Data
Source=C:\Datos \Datos.mdb;"
cnMiConn.Open()

'Abre la base de datos
rsMiTabla.Open( "SELECT * FROM [tTabla]", cnMiConn,
ADODB.CursorTyp eEnum.adOpenDyn amic, ADODB.LockTypeE num.adLockOptim istic, 0)

End Sub

....

Para manipular los datos utilizas los siguientes métodos:
1- Insertar un nuevo registro
'Inserta un nuevo registro en la tabla
rsMiTabla.AddNe w()
rsMiTabla.Field s("Campo1").Val ue = TextBox1.Text
rsMiTabla.Field s("Campo2").Val ue = ComboBox1.Text
rsMiTabla.Field s("Campo2").Val ue = CheckBox1.Check ed
rsMiTabla.Updat e()

2- Eliminar un registro
'Elimina el registro actual
rsMiTabla.Delet e()

3- Ir al primer registro
rsMiTabla.MoveF irst()

4- Ir un registro atrás
rsMiTabla.MoveP revious()

5- Ir un registro adelante
rsMiTabla.MoveN ext()

6- Ir al último registro
rsMiTabla.MoveL ast

Existen dos propiedades que te indican cuando se ha llegado al principio o
al final de la tabla. Estas propiedades te ayudarán a saber si existen
registros en la tabla. Las propiedades se llaman BOF y EOF y son de tipo
Boolean.
BOF se utiliza para saber si estás en el principio de la tabla
EOF se utiliza para saber si estás en el final de la tabla
Si las dos propiedades son verdaderas entonces no existen registros en la
tabla.
Funciona de la siguiente manera. Cuando en una tabla estás en el primer
registro válido su posición es 1 y cuando estás en el final su posición es
la cantidad de registros que existan. Si te mueves un registro atrás la
posición cambia a 0 y BOF se pone verdadero. Si estás en el final y te
mueves un registro adelante la posición es la cantidad de registros que
existen en la tabla + 1 y EOF se pone verdadero.

Ejemplo de código:

....

Public Sub MoverPrincipio( )
'Se mueve al principio de la tabla
rsMiTabla.MoveF irst()
End Sub
Public Sub MoverAnterior()
'Se mueve un registro atrás
rsMiTabla.MoveP revious()

'Si se está en el principio de la tabla se mueve al primer registro válido
If (rsMiTabla.BOF = True) Then
rsMiTabla.MoveF irst()
End If
End Sub
Public Sub MoveNext()
'Se mueve un registro adelante
rsMiTabla.MoveN ext()

'Si se está en el final de la tabla se mueve al último registro válido
If (rsMiTabla.EOF = True) Then
rsMiTabla.MoveL ast()
End If
End Sub
Public Sub MoveLast()
rsMiTabla.MoveL ast()
End Sub

....

Querido amigo, creo que es suficiente para que puedas manipular una base de
datos de Access en VB.NET utilizando ADO. Si quieres profundizar más al
respecto te recomiendo que vayas a la ayuda.

Fuccio DaVietre
"josephrtho mas" <ex***********@ yahoo.com.sg> escribió en el mensaje
news:02******** *************** *****@phx.gbl.. .
hi..
i am using ASP.NET with VB.NET to connect to a MS Access
database...
can someone pls tell me how do i make the sql statement to
insert a new record into the existing table pls??
also how do i filter data?
i mean lets say i wanna filter the NAME field and get all
the names starting with
"Ja"
can someone pls tell how do i write the sql statement to
do that pls?

tks a lot...

Nov 18 '05 #3
i am very sorry...can u speak english pls???

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4
hi...
tks a lot...but i am very sorry....can u pls write it in english???
tks a lot...

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #5
Jos
josephrthomas wrote:
hi..
i am using ASP.NET with VB.NET to connect to a MS Access
database...
can someone pls tell me how do i make the sql statement to
insert a new record into the existing table pls??
strSQL = "INSERT INTO myTable
(myTextField1,m yNumberField2) VALUES ('test', 123);"
also how do i filter data?
i mean lets say i wanna filter the NAME field and get all
the names starting with
"Ja"


strSQL = "SELECT * FROM myTable WHERE NAME LIKE 'Ja%';"

--

Jos
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
8357
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except for '5'. So in his switch statement, he omits a case for '5':
7
35674
by: Bob | last post by:
Currently I am using this statement to translate 3 fields in my db thru Visual Basic. I import the data from one table to another then call the IFF statements and the NewDate to translate the fields. Can this be done in an Access db? I am trying to learn how to do these things in Access vs Visual Dim strIIF As String Dim sstrIIF As String Dim strNewDate As Date
11
50365
by: Colleyville Alan | last post by:
I posted that I was having trouble with a SQL statement that was working in the SQL window, but not in VBA. I have since discovered that when I create the string in VBA it is over 1023 characters long. When I copy this string into the SQL window, it splits into two lines, one of 1023 and the remainder in the next. When I remove that break, the query runs just fine. Since Access tells me that a string can hold 10^16 (64k), it did not...
14
6107
by: Ryan | last post by:
I want to do the following SQL statement in Access. However, it won't allow me to have the secondary part of my join statement and tells me that this is not supported. OK, so Access doesn't support it, but there must be an alternative. I can add the part 'D.Dealer_Code' to the where clause, but because of the way that the statement is executed, it excludes data that I want. My SQL statement is perfectly leagal and works fine, but Access...
3
4611
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my date fields. Here's the setup: I'm using Access 97 (I know it's old. But, it's the tool they give me to work with) My working knowledge of SQL is on the low side. My working knowledge of VBA is beginner.
7
6672
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double checked, and the insert works fine (tried to use it from access)... im using visual C# express 2k5... what could be wrong? thanks!
10
2369
by: John Smith | last post by:
Can you do a Select Statement within a Select Statement? I want to build a query similar to queries built in Access which link to other queries but using only SQL Statements. Is it possible? If so, how do you do it? Thanx in adv.
6
2691
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the person wants to receive a newsletter and 0 no, don't want to receive it. Now.....when trying to create an UPDATE statement I am running into problems writing the code for it. I had issues before with missing commas but now that the commas are there...
4
3030
by: Dave | last post by:
I have a field with data type of memo in my access database. I run a query from c# to access this field and it cuts off my string to only 255 characters. If i run this query directly in access it works fine. If i run this query without the iif statement it works fine. It only cuts off my string when i run this query in c# WITH the iif statement. Here is the statement that doesn't work. SELECT IIF(ISNULL(t1.field1), t2.field1,...
7
2701
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about the goals -- the make statement is mostly syntactic sugar for:: class <name> <tuple>: __metaclass__ = <callable>
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10259
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.