-
ASP insert into SQL with VB
i foundthis code on DEVX, and have copied into my code, i used the following as my connection string info
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=server=spumbu\sqlexpress;database=oss;Trusted_Connection=Yes")
and my strsql string was
INSERT INTO WebRequestCat(Name, EmailAddress) VALUES (N'txt1', N'txt2')
although when testing it just hangs on load . ? any ideas please
as i am now officially dumbstruck lol .?
Dim strSQL as string = "INSERT INTO TableName(Field1, Field2) Values(Val1, Val2)"
'Where val1 and val2 are parameters
Dim objConnection as SQLConnection("your connection string here")
Dim objCommand as SQLCommand(strSQL, objConnection)
objConnection.Open()
objCommand.Parameters.Add("@Val1", TextBox1.Text)
objCommand.Parameters.Add("@Val2", TextBox2.Text)
objCommand.ExecuteNonQuery()
objConnection.Close
Thanks in advance
Rob
-
i think there are some references that i need to add, as since i sort of into VB6 i do know that there is always a reference that needs adding
please any help is always apreciated
Rob
-
Hi Rob,
have a look at this page - it has a good example of what you are trying to do.
http://www.vistadb.net/vistadb3/tuto...rtRows-VB.aspx
Hope this helps
Graham
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, and if they get mad, you are a mile away and you have their shoes ;-)
http://www.grahamrobinsonsoftware.com
-
thanks for the quick and helpful response , and i will try this when i get home tonight,
by the way i like your moto about walking a mile in their shoes lol
quick question, is there any benefits in using DDA in comparison to adodb .?
thanks
Rob
-
If you are using any form of .NET technology, you should not be using adodb for anything.
For .NET database work, always use ADO.NET
-
Hi All
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim ra As Integer
myConnection = New SqlConnection("server=gbrltsxpp-12332\sqlexpress;uid=sa;pwd=mikki1;database=test")
myConnection.Open()
myCommand = New SqlCommand("Insert into test1 'ID','Data1','Dat2' values 'textbox1.text','textbox2.text ','textbox3.text', myConnection)
ra = myCommand.ExecuteNonQuery()
MsgBox("Completed")
myConnection.Close()
with the above code, 'mycommand' seems to throw up errors about the textbox not being in context,
i have tried with colons, comma's and nothing at all, however it tells me the same thing for allof them, can anyone see what i might be missing
thanks very much in advance for all your help
Rob
-
You are missing parentheses around your VALUES clause and field list. Also, field names do not need single quotes
Code:
Dim sSQL As String
sSQL = "INSERT INTO test1 (ID, Data1, Dat2) " 'id, data1 and dat2 should be the names of fields in your table
sSQL = sSQL & "VALUES ("' & textbox1.text & "', '" & textbox2.text & "', '' & textbox1.text & "')"
I broke it up for readibility.
-
thanks mate for your help, that worked like a treat, but if i may, i wish to ask another question please
my behind the scene code is as follows
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim ra As Integer
myConnection = New SqlConnection("server=gbrltsxpp-12332\sqlexpress;uid=sa;pwd=mikki1;database=test")
myConnection.Open()
myCommand = New SqlCommand("INSERT INTO test1 (ID, Data1, Data2)VALUES ('" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox1.Text & "')", myConnection)
ra = myCommand.ExecuteNonQuery()
MsgBox("Completed")
myConnection.Close()
End Sub
End Class
however as you can see my code sits under the Button1_click method but runs as soon as the page starts, is there anyway to stop this from happenening .?
thanks in advance
Rob
-
Does the button have focus when the page opens?
-
i dont want to sound like i know much as i dont really besides vb6, and in order to set things in order i used to use Tabindex and Tapstop properties,
how would i go about looking into finding out if it is or not .?
thanks in advance
Rob
Similar Threads
-
By scottd in forum Database
Replies: 0
Last Post: 01-03-2007, 12:02 PM
-
Replies: 8
Last Post: 06-25-2001, 12:37 AM
-
By Dave V in forum vb.announcements
Replies: 0
Last Post: 04-24-2001, 08:55 PM
-
By Dave V in forum vb.announcements
Replies: 0
Last Post: 04-08-2001, 02:01 PM
-
By Bob Hines in forum Database
Replies: 7
Last Post: 04-27-2000, 11:14 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|