473,239 Members | 1,545 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,239 software developers and data experts.

Web Database (Insert)

'Full source
'Insert, delete and update don't work
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents Button1 As
System.Web.UI.WebControls.Button
Protected WithEvents Button2 As
System.Web.UI.WebControls.Button
Protected WithEvents Button3 As
System.Web.UI.WebControls.Button
Protected WithEvents Button4 As
System.Web.UI.WebControls.Button
Protected WithEvents Button5 As
System.Web.UI.WebControls.Button
Protected WithEvents TextBox1 As
System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox2 As
System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox3 As
System.Web.UI.WebControls.TextBox
Protected WithEvents DataGrid1 As
System.Web.UI.WebControls.DataGrid
Dim cnn1 As New OleDb.OleDbConnection()
Dim dap1 As New OleDb.OleDbDataAdapter()
Dim das1 As New System.Data.DataSet()
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Button1.Text = "Select"
Button2.Text = "Delete"
Button3.Text = "Update"
Button4.Text = "Insert"
Button5.Text = "Refresh"
'Tab index property
Button1.TabIndex = 2
TextBox1.TabIndex = 1
TextBox2.TabIndex = 3
TextBox3.TabIndex = 4
Button2.TabIndex = 5
Button3.TabIndex = 6
Button4.TabIndex = 7
Button5.TabIndex = 8
End If
Dim str1 As String = "Provider =
Microsoft.Jet.OLEDB.4.0;"
str1 &= "Data Source = c:\Archivos de
programa\" & "Microsoft Office\Office10
\Samples\Northwind.mdb"
cnn1.ConnectionString = str1
'Invoke Refresh to populate grid control
Refresh()
End Sub
Sub Refresh()
Dim cmd1 As New OleDb.OleDbCommand()
With cmd1
.Connection = cnn1
.CommandText = "SELECT * FROM
VBDotNetShippers"
End With
Dim dap1 As New OleDb.OleDbDataAdapter(cmd1)
dap1.Fill(das1, "VBDotNetShippers")
DataGrid1.DataSource = (das1.Tables
("VBDotNetShippers"))
DataGrid1.DataBind()
End Sub

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim int1 As Integer
For int1 = 0 To das1.Tables(0).Rows.Count - 1
If das1.Tables(0).Rows(int1)(0) = CInt
(TextBox1.Text) Then
TextBox2.Text = das1.Tables(0).Rows
(int1)(1)
TextBox3.Text = das1.Tables(0).Rows
(int1)(2)
End If
Next
End Sub

Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
If IsThere(TextBox1.Text) = False Then
Response.Write("DELETE exit trap")
Exit Sub
End If
Dim str1 As String = "DELETE FROM
VBDotNetShippers " & "WHERE ShipperID=" & TextBox1.Text
'Run SQL String
RunSQLString(str1)
'Clear controls and refresh from Northwind
ClearAllAndRefresh()
End Sub

Private Sub Button3_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
If IsThere(TextBox1.Text) = False Then
Response.Write("UPDATE exit trap")
Exit Sub
End If
'Specify update SQL string
Dim str1 As String = "UPDATE
VBDotNetShippers " & "SET CompanyName='" & TextBox2.Text
& "', " & "Phone='" & TextBox3.Text & "' WHERE
ShipperID=" & TextBox1.Text
'Run SQL string
RunSQLString(str1)
ClearAllAndRefresh()
End Sub

Private Sub Button4_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button4.Click
'Specify insert SQL string
Dim str1 As String = "INSERT INTO
VBDotNetShippers " & "(CompanyName, Phone) VALUES('" &
TextBox2.Text & "', '" & TextBox3.Text & "')"
RunSQLString(str1)
ClearAllAndRefresh()
End Sub

Private Sub Button5_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button5.Click
'Clear controls and refresh from Northwind
ClearAllAndRefresh()
End Sub
Function IsThere(ByVal str1) As Boolean
Dim cmd1 As New OleDb.OleDbCommand()
Dim int1 As Integer
'Run SQL statement to determine if ShipperID
'column value exists
With cmd1
.Connection = cnn1
.CommandText = "SELECT * FROM
VBDotNetShippers " & "WHERE ShipperID=" & str1
cnn1.Open()
int1 = .ExecuteScalar
cnn1.Close()
End With
'Return true if int1 is greater than 0
If int1 > 0 Then Return True
End Function
Sub RunSQLString(ByVal str1 As String)
'Instantiate OleDBCommand object
Dim cmd1 As New OleDb.OleDbCommand()
'Assing Connection and CommandText property
'values before invoking the commad
With cmd1
.Connection = cnn1
.CommandText = str1
cnn1.Open()
.ExecuteNonQuery()
cnn1.Close()
End With
End Sub
Sub ClearAllAndRefresh()
das1.Clear()
Refresh()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub

End Class
Nov 20 '05 #1
1 2523
Hello,

"Primillo" <pr********@hotmail.com> schrieb:
'Full source
'Insert, delete and update don't work


Doesn't work? Error message?

This is a VB.NET language group. Notice that you will have a better
chance to get an answer if you post to the ADO.NET newsgroup in future:

news://msnews.microsoft.com/microsof...amework.adonet

Web interface:

http://msdn.microsoft.com/newsgroups...amework.adonet

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2

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

Similar topics

2
by: Simon | last post by:
Hi, I am having a little problem with my PHP - MySQl code, I have two tables (shown below) and I am trying populate a template page with data from both. <disclaimer>Now I would like to say my...
6
by: Clay Beatty | last post by:
When you create database diagrams in Enterprise Manager, the details for constructing those diagrams is saved into the dtproperties table. This table includes an image field which contains most of...
3
by: Bill MacLean | last post by:
-- Example Schema posted at end of message: --- For reporting purposes, I need to build a single comma delimited string of values from the "many" table of a database. The easiest way to see...
1
by: Tim Pascoe | last post by:
I've been trying to get the scripts posted earlier to the group by Clay Beatty to work properly. Using the three components he posted, I have managed to get a new SP generated. However, when I...
3
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection...
7
by: Jared Evans | last post by:
I developed a console application that will continually check a message queue to watch for any incoming data that needs to be inserted into MS SQL database. What would be a low-cost method I...
2
by: altergothen | last post by:
Hi there I am a newbie to ASP.Net - Please Help! I am trying to insert the values of my variables into a database. If I try the following it works perfectly: string insertQuery = "INSERT into...
3
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news...
9
by: Jerim79 | last post by:
I am no PHP programmer. At my current job I made it known that I was no PHP programmer during the interview. Still they have given me a script to write with the understanding that it will take me a...
2
by: astolpho | last post by:
I am using a slightly outdated reference book on J2EE programming. It gives 2 methods of creating a database used in its casestudies. The first is an ANT script that gives the following output: ...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.