|
-
Aug 5th, 2008, 02:19 PM
#1
Thread Starter
Member
vb6 +Access db insert into entire collum
hi i have a form with :
DataGrid1
Adodc1
textbox
Command2
on form load i have this code :
Code:
Private Sub Form_Load()
Adodc1.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & (App.Path & "\Database\data.mdb") & ";Persist Security Info=False;Jet OLEDB:Database Password=password")
Adodc1.RecordSource = "Select * from phonia"
Set DataGrid1.DataSource = Adodc1
End Sub
i want at Private Sub Command2_Click()
to insert into table phonia and colum 2008 the value of text1.text
but i want to insert the value at entire collum
sample : if text1.text = 2
table phonia
colum1 | 2008 |
mike 2
suzan 2
nick 2
george 2
clif 2
something like that.
in entire colum 2008 i want to insert velue text1.text
thanks
-
Aug 5th, 2008, 02:31 PM
#2
Addicted Member
Re: vb6 +Access db insert into entire collum
I'm not really sure how you would do that with an data control although the SQL statement is simple enough.
Code:
UPDATE phonia SET 2008 = " & text1.text
So many things I could say like don't use Bound Controls, your column names really shouldn't be just a number, and while it takes longer setting up connections without bound controls gives you alot more flexibility.
Simple little bugs 13 : Me 1
Law of Bugs - That one bug you missed will be found almost immediately, by your customer.
I wonder if anyone has ever asked for a User Surly interface?
-
Aug 5th, 2008, 02:50 PM
#3
Thread Starter
Member
Re: vb6 +Access db insert into entire collum
 Originally Posted by Veritas2.0
I'm not really sure how you would do that with an data control although the SQL statement is simple enough.
Code:
UPDATE phonia SET 2008 = " & text1.text
So many things I could say like don't use Bound Controls, your column names really shouldn't be just a number, and while it takes longer setting up connections without bound controls gives you alot more flexibility.
it is a sample project and sample names, i just make some tests
dont realy matters what the name at the table you may give me some full example Private Sub Command2_Click()
thanks
-
Aug 5th, 2008, 03:30 PM
#4
Addicted Member
Re: vb6 +Access db insert into entire collum
Well If you are going to stick wth the bound controls I'm pretty sure what you are going to have to do is cycle through all the records and change the value in each one. I could be wrong though.
I still recommend you just scrap the data controls and connect manually to the database.
Code:
Public myConnection As ADODB.connection
Set myConnection = New ADODB.connection
myConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & (App.Path & "\Database\data.mdb") & ";Persist Security Info=False;Jet OLEDB:Database Password=password"
myConnection.Execute "UPDATE phonia SET 2008 = " & text2.Text
Simple little bugs 13 : Me 1
Law of Bugs - That one bug you missed will be found almost immediately, by your customer.
I wonder if anyone has ever asked for a User Surly interface?
-
Aug 5th, 2008, 09:32 PM
#5
Junior Member
Re: vb6 +Access db insert into entire collum
Try this one:
vb Code:
Private Sub Command2_Click()
Adodc1.RecordSource = "Select * from phonia" 'or any query that you want to edit
Adodc1.Refresh
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
Adodc1.RecordSet.Edit
Adodc1.Recordset.Fields("2008") = Text1.Text
Adodc1.RecordSet.Update
Adodc1.Refresh
Loop
End Sub
-
Aug 5th, 2008, 09:34 PM
#6
Junior Member
Re: vb6 +Access db insert into entire collum
Oh I for got
You got to Insert this after the Adodc1.Recordset.Update code
Adodc1.RecordSet.MoveNext
Like this:
vb Code:
Adodc1.RecordSet.Edit
Adodc1.Recordset.Fields("2008") = Text1.Text
Adodc1.RecordSet.Update
Adodc1.RecordSet.MoveNext
Adodc1.Refresh
-
Aug 6th, 2008, 12:43 AM
#7
Thread Starter
Member
Re: vb6 +Access db insert into entire collum
 Originally Posted by kasmot
Oh I for got
You got to Insert this after the Adodc1.Recordset.Update code
Adodc1.RecordSet.MoveNext
Like this:
vb Code:
Adodc1.RecordSet.Edit
Adodc1.Recordset.Fields("2008") = Text1.Text
Adodc1.RecordSet.Update
Adodc1.RecordSet.MoveNext
Adodc1.Refresh
Method or data member not found : Adodc1.Recordset.Edit !
i think that Edit method doesn't exist in ADO
Last edited by Chrisad; Aug 6th, 2008 at 01:00 AM.
-
Aug 6th, 2008, 01:00 AM
#8
Re: vb6 +Access db insert into entire collum
All these troubles are because of using bound controls as mentioned earlier. You will save yourself alot of time and headaches by switching to pure ADO code.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 6th, 2008, 03:56 AM
#9
Thread Starter
Member
Re: vb6 +Access db insert into entire collum
so there no any other option to do that ?
thanks
-
Aug 6th, 2008, 07:02 AM
#10
Re: vb6 +Access db insert into entire collum
There are other options (including getting bound controls working), but they generally need much more effort to write, waste time/memory when running, and fewer people are able to help you - the people who help the most with database questions are unlikely to be much use.
You should be following the suggestions Veritas2.0 made, and I'd recommend reading the link in post #2, as it contains several reasons why that is the way to go.
-
Apr 2nd, 2010, 02:04 PM
#11
Lively Member
Re: vb6 +Access db insert into entire collum
-
Apr 2nd, 2010, 02:10 PM
#12
Re: vb6 +Access db insert into entire collum
 Originally Posted by vb6beginer
byee
Why did you bump this thread?!?
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
|
Click Here to Expand Forum to Full Width
|