473,407 Members | 2,306 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,407 software developers and data experts.

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 6687
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.
"josephrthomas" <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.Connection 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.Connection()
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.Connection()
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.ConnectModeEnum.adModeReadWrite

'Tiempo límite en segundos para efectuar la conexión
cnMiConn.ConnectionTimeout = 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.Provider = "Microsoft.Jet.OLEDB.4.0"

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

'Abre la base de datos
rsMiTabla.Open("SELECT * FROM [tTabla]", cnMiConn,
ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic, 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.AddNew()
rsMiTabla.Fields("Campo1").Value = TextBox1.Text
rsMiTabla.Fields("Campo2").Value = ComboBox1.Text
rsMiTabla.Fields("Campo2").Value = CheckBox1.Checked
rsMiTabla.Update()

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

3- Ir al primer registro
rsMiTabla.MoveFirst()

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

5- Ir un registro adelante
rsMiTabla.MoveNext()

6- Ir al último registro
rsMiTabla.MoveLast

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.MoveFirst()
End Sub
Public Sub MoverAnterior()
'Se mueve un registro atrás
rsMiTabla.MovePrevious()

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

'Si se está en el final de la tabla se mueve al último registro válido
If (rsMiTabla.EOF = True) Then
rsMiTabla.MoveLast()
End If
End Sub
Public Sub MoveLast()
rsMiTabla.MoveLast()
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
"josephrthomas" <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,myNumberField2) 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
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...
7
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...
11
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...
14
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...
3
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...
7
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...
10
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...
6
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 ...
4
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...
7
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...
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
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
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,...
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,...
0
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...
0
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,...
0
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...

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.