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
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.
Re: vb6 +Access db insert into entire collum
Quote:
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
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
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
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
Re: vb6 +Access db insert into entire collum
Quote:
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
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.
Re: vb6 +Access db insert into entire collum
so there no any other option to do that ?
thanks
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.
Re: vb6 +Access db insert into entire collum
Re: vb6 +Access db insert into entire collum
Quote:
Originally Posted by
vb6beginer
byee
Why did you bump this thread?!?