| | |
insert into sql select statement
Thread Solved
![]() |
•
•
Join Date: Jul 2007
Posts: 189
Reputation:
Solved Threads: 16
Here I am again with my next sql problem. I'm not sure if I can use insert into for what I need. What I want to do is the following.
My tables
I have tblreminder with userid workid workdate
I have tbluser with userid and username
My textbox
I have txtuser
Variables
idwork
mydate
I want to add new record to tblreminder
tblreminder.userid = select userid from tbluser where username = txtuser
Here is my code that's not working
adoreminder.RecordSource = "INSERT INTO tblreminder(user-id) SELECT tbluser.id FROM tbluser WHERE tbluser.Name = '" & txtname.Text & "'"
Can anybody help me?
My tables
I have tblreminder with userid workid workdate
I have tbluser with userid and username
My textbox
I have txtuser
Variables
idwork
mydate
I want to add new record to tblreminder
tblreminder.userid = select userid from tbluser where username = txtuser
Here is my code that's not working
adoreminder.RecordSource = "INSERT INTO tblreminder(user-id) SELECT tbluser.id FROM tbluser WHERE tbluser.Name = '" & txtname.Text & "'"
Can anybody help me?
vb Syntax (Toggle Plain Text)
adoreminder.RecordSource="INSERT INTO tblreminder(userid)(SELECT tbluser.id FROM tbluser WHERE tbluser.Name = '" & txtname.Text & "')";
if not put a duoblequote on the subquery,like this:
vb Syntax (Toggle Plain Text)
adoreminder.RecordSource="INSERT INTO tblreminder(userid)("SELECT tbluser.id FROM tbluser WHERE tbluser.Name = '" & txtname.Text & "'")";
Hi PlusPlus,
What is AdoReminder....?
if it is a Connection object, then use Execute method..
say:
Wrap complicated column names with square breackets.. (- in ur case)
always UnderScore ( _ ) is better than -
REgards
Veena
What is AdoReminder....?
if it is a Connection object, then use Execute method..
say:
vb Syntax (Toggle Plain Text)
adoreminder.Execute = "INSERT INTO tblreminder([user-id]) SELECT tbluser.id FROM tbluser WHERE tbluser.Name = '" & txtname.Text & "'"
Wrap complicated column names with square breackets.. (- in ur case)
always UnderScore ( _ ) is better than -
REgards
Veena
•
•
Join Date: Jul 2007
Posts: 189
Reputation:
Solved Threads: 16
adoreminder is adodc and it doesn't recognize execute. I have code that's working with two ado, I thought I can do it in one, but I can't get it right. Here is my code with two ados that's working.
Can you help to put it into one(if that's more correct)
Can you help to put it into one(if that's more correct)
•
•
•
•
adouser.RecordSource = "SELECT * FROM tbluser WHERE Name = '" & txtname.Text & "'"
adouser.Refresh
If adouser.Recordset.EOF = True Then
Call MsgBox("Kontrollieren Sie den Namen", , "Ungültiger Name")
Exit Sub
End If
adoreminder.RecordSource = "SELECT * FROM tblreminder"
adoreminder.Refresh
adoreminder.Recordset.AddNew
adoreminder.Recordset("User-Id") = adouser.Recordset("id")
adoreminder.Recordset("Bau-Id") = frmBaukalender.adobau.Recordset("ID")
adoreminder.Recordset("Erinnerungsdatum") = MonthView1.Value
adoreminder.Recordset("Notizen") = txtNotiz.Text
adoErinnerung.Recordset.Update
Last edited by plusplus; Oct 17th, 2007 at 7:12 am.
Hi,
Data Controls, may be OK, for beginners, but when you are developing complete Client-Server system, you need to have a Robust connection object, which you can have shared throught out your whole project ( multiple Forms).. Data Controls are Form Level.. Though you can access in other forms also. But having a Connection Object can give more flexibility in writing Execute Statements(DML Statements to any Table). It works on the database as whole, where as DataControls work on Table-/SQL Statemnt level.
Regards
Veena
Data Controls, may be OK, for beginners, but when you are developing complete Client-Server system, you need to have a Robust connection object, which you can have shared throught out your whole project ( multiple Forms).. Data Controls are Form Level.. Though you can access in other forms also. But having a Connection Object can give more flexibility in writing Execute Statements(DML Statements to any Table). It works on the database as whole, where as DataControls work on Table-/SQL Statemnt level.
Regards
Veena
![]() |
Similar Threads
- Complicated SQL SELECT Statement - NEWBIE (MS SQL)
- Hi,Need help on sql select statement structure (MS SQL)
- SQL select statement help (MS Access and FileMaker Pro)
- Question about SELECT statement (MySQL)
- Getting current value in Select Statement (MS SQL)
- cfselect issue trying to get results from a sql select statement (ColdFusion)
- Program Problem with a select statement to access Data base (C)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Help with Message Boxes
- Next Thread: ms flex grid
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic beginner birth bmp calculator cd cells.find click client code college connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows





