0% found this document useful (0 votes)
76 views

Default1 Detailsviewpageeventargs: "Provider Microsoft - Ace.Oledb.12.0 Data Source " "Mydb1.Accdb"

This code connects to an Access database using OleDb and inserts a record into a table. It opens a connection, builds an INSERT statement, executes it with ExecuteNonQuery, and displays a message on success. It also handles exceptions. Additional code connects to a SQL Server database and performs SELECT statements to retrieve data and counts using a SqlDataReader and ExecuteScalar.

Uploaded by

pragms
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Default1 Detailsviewpageeventargs: "Provider Microsoft - Ace.Oledb.12.0 Data Source " "Mydb1.Accdb"

This code connects to an Access database using OleDb and inserts a record into a table. It opens a connection, builds an INSERT statement, executes it with ExecuteNonQuery, and displays a message on success. It also handles exceptions. Additional code connects to a SQL Server database and performs SELECT statements to retrieve data and counts using a SqlDataReader and ExecuteScalar.

Uploaded by

pragms
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Imports System.Data.

OleDb
Imports System.Data
Partial Class Default1
Inherits System.Web.UI.Page
Protected Sub DetailsView1_PageIndexChanging(sender As Object, e As DetailsViewPageEventArgs) Handles
DetailsView1.PageIndexChanging
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connection As OleDb.OleDbConnection
Dim mydb, mystr As String

mystr = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Server.MapPath("mydb1.accdb"))


connection = New OleDb.OleDbConnection(mystr)
connection.Open()
mydb = "INSERT INTO [Name] ([emailid], [password]) VALUES ('zasdasd', 'zewe')"
Dim run = New OleDb.OleDbCommand

Try
run = New OleDbCommand(mydb, connection)
run.ExecuteNonQuery()
MsgBox("connection opened")
Catch ex As Exception
Label1.Text = ex.Message
End Try
End Sub
End Class

-=----------DeleteCommand="DELETE FROM [Name] WHERE (([emailid] = ?) OR ([emailid] IS NULL AND ? IS NULL))"


InsertCommand="INSERT INTO [Name] ([emailid], [password]) VALUES (?, ?)" ProviderName="<%$
ConnectionStrings:ConnectionString2.ProviderName %>"
SelectCommand="SELECT [emailid], [password] FROM [Name]" UpdateCommand="UPDATE [Name] SET
[password] = ? WHERE (([emailid] = ?) OR ([emailid] IS NULL AND ? IS NULL))">

SELECT Name.emailid, Name.password FROM Name WHERE (((Name.emailid)="prag") AND


((Name.password)="shah"));

SQL
Dim myconnection As New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=|
DataDirectory|\Database1.mdf;Integrated Security=True;Connect Timeout=30")
myconnection.Open()
Label1.Text = myconnection.State
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim myconnection As New SqlConnection("Data
Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated
Security=True;Connect Timeout=30")
' myconnection.Open()
Label1.Text = myconnection.State
Dim myCommand As New SqlCommand()
myCommand.Connection = myconnection
myCommand.CommandText = "SELECT * FROM [Table] where password='shaw'"
Dim reader As SqlDataReader
Try
myconnection.Open()
reader = myCommand.ExecuteReader()
reader.Read()
Label1.Text = reader("emailid").ToString()
'txtID.Text = reader("au_id").ToString()
reader.Close()
myconnection.Close()

Catch ex As Exception
Label1.Text=ex.Message
End Try
End Sub
End Class

===========
myCommand.CommandText = "SELECT count(*) FROM [Table] where password='shaw'"
Dim reader As SqlDataReader

Try
myconnection.Open()
Dim count As Integer = CType(myCommand.ExecuteScalar(), Integer)
MsgBox(count)

Dim myCommand As New SqlCommand()


Dim vcounter As Integer
myCommand.Connection = myconnection
'myCommand.CommandText = "SELECT count(*) FROM [Table] where emailid = '" &
TextBox1.Text & "'"
myCommand.CommandText = "SELECT count(*) FROM [Table] where emailid = '" &
TextBox1.Text & "' and password ='" & TextBox2.Text & "'"

You might also like