|
What do you mean that the oledbdataadapter object doesn't reflect the change? Because if you mean that it doesn't show the updated data, then you are looking at the wrong object. The DataAdapter is used to update the database, but it doesn't contain the data. The DataSet object does. That would DsAsets1 in your code. How are you displaying your data? How are you determining that the change is not being reflected in your app?
|
|
|
|
|
I am using textboxes to display the data and a navigator to browse through it. but the dataset cant pick up the newly updated record unless i restart my application.
this is the code i use to insert data in the database. I'll try and keep it short by just giving you the insert statement.
mycmd = "Insert into Assets(AssetID,AssetDescription,AssetCategory,Department,DateAcquired,Cost,ModelNumber,DepreciationPercent,MaintenanceType,comment,Location) Values ('" & assetId & "','" & assetdescription & "', '" & assetcategory & "', '" & department & "', #" & dateacquired & "#, '" & costprice & "', '" & modelnumber & "', '" & depreciation & "', '" & maintenancetype & "', '" & comment & "','" & location & "')"
conn.Open()
mycommand.Connection = conn
mycommand.CommandText = mycmd
myadapter.InsertCommand = mycommand
myadapter.InsertCommand.ExecuteNonQuery()
conn.Close()
and this is the code i use to retrieve the data from the database.
Try
DsAsets1.Clear()
OleDbDataAdapter1.Fill(DsAsets1)
count()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
when I search for the data using the following code, I could see the data but the dataset can not pick it up
conn.Open()
Dim cmd As OleDbCommand = conn.CreateCommand()
cmd.CommandText = "SELECT AssetId, assetDescription, assetCategory, Department, DateAcquired, Cost, ModelNumber, DepreciationPercent, MaintenanceType, Comment,Location FROM Assets WHERE AssetID = '" + assetId + "'"
Dim reader As OleDbDataReader = cmd.ExecuteReader()
reader.Read()
If reader.HasRows Then
txtAssetNo.Text = (reader.GetString(0))
txtDescription.Text = (reader.GetString(1))
cmbCategory.Text = (reader.GetString(2))
cmbDepartment.Text = (reader.GetString(3))
dtpDateAcquired.Text = (reader.GetDateTime(4))
txtCostPrice.Text = (reader.GetDecimal(5))
txtModelNumber.Text = (reader.GetString(6))
txtDepreciation.Text = (reader.GetDecimal(7))
cmbMainType.Text = (reader.GetString(8))
txtComment.Text = (reader.GetString(9))
txtLocation.Text = (reader.GetString(10))
BindingNavigatorPositionItem.Text = 1
BindingNavigatorCountItem.Text = "of " & "{1}"
BindingNavigatorMovePreviousItem.Enabled = False
BindingNavigatorMoveNextItem.Enabled = False
txtFind.Text = ""
|
|
|
|
|
Do you have the .SelectCommand.CommandText set in the OleDbDataAdapter1 object before you retrieve data from the database? It should be the same as your SELECT when you are using the OleDbDataReader. You also must have the connection set, but I'm assuming you just didn't show us that code. So how are you tying the DataSet to the textbox/navigation controls? Are they showing the OLD data, or do they just get cleared after you perform an update?
You should try to put a breakpoint on the line right AFTER you've filled the DataSet. Then quickwatch the dataset and look at the data you have brought back. Here you will be able to see if the DataSet is actually bringing back the updated data. If the data is the updated data, then the problem is however you are connecting your textboxes to the DataSet.
I do things very different than you, so I'm kind of confused by your code in general. If you are just going do an execute non query you can do that with just a Command object, you don't need the DataAdapter. Like this:
mycmd = "Insert into Assets(AssetID,AssetDescription,AssetCategory,Department,DateAcquired,Cost,ModelNumber,DepreciationPercent,MaintenanceType,comment,Location) Values ('" & assetId & "','" & assetdescription & "', '" & assetcategory & "', '" & department & "', #" & dateacquired & "#, '" & costprice & "', '" & modelnumber & "', '" & depreciation & "', '" & maintenancetype & "', '" & comment & "','" & location & "')"
conn.Open()
mycommand.Connection = conn
mycommand.CommandText = mycmd
mycommand.ExecuteNonQuery()
conn.Close() Also, you may want to look into using parameters for insert statements like this, to avoid SQL Injection. And there are ways to update the DataSet and have it automatically generate the proper Insert or Update or Delete statements for you. You may want to look at some articles about this if you are interested.
|
|
|
|
|
when i perform an update, the data in the database get updated but the dataset does not refresh to show this update even when i cleared and refill data into it. I have also tried to insert a breakpoint on the line right after filling the dataset and then quickwatch the dataset but it doesnt contain the updated record.
|
|
|
|
|
Hi,
I want to pass a string array to a c++ function, which is the interface of my ActiveX control.
My previous VB6 in the following works fine:
Dim arrayStr As Variant
Redim arrayStr(5) As String
'call the C++ function
fun(arrayStr)
the definition of the C++ is like this:
fun(Variant Far * strarray);
Now I want to update the VB code from version 6.0 to .net. but I always got a type mismatch error or other error if I do it like this:
Dim arrayStr() As String
...
fun(arrayStr)
Any help will be appreciated!
|
|
|
|
|
How can i send text to another application textbox?
Thanks
|
|
|
|
|
Hi,
I am using VB Express 2005 in order to create a from which can contain an excel document. I have been able to open the excel document no problem by using a webrowser component on the form. Unfortunately I cannot view any of Excels menus or toolbars. Can Anyone tell me how to do this ? I have looked at some code online which uses the webbrower.document to create an object by which you can then save, and also view toolbars but I can't get this to work. Any help would be greatly appreciated.
|
|
|
|
|
|
How can i convert a speech to text
Bizzo
|
|
|
|
|
How come when you google for a programming concept (something that you should consider trying), you almost always end up back at The Code Project?
http://www.codeproject.com/audio/SAPI.asp[^]
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Guffa wrote: you almost always end up back at The Code Project?
Because this is the best site for programming information anywheres on the 'net
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
How do you lookup a value that appears more than once in a column?
For example
a 10
b 50
g 89
f 7
t 58
a 56
a 25
a 69
How can i select all the a's and display their individual results? eg
a 10
a 25
a 69
Thanks for your help
|
|
|
|
|
How can I access the registry location HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrnetVersion\App Paths ?
Anyone knows this ? Please help.
Thanks in advance.
Sekhar
|
|
|
|
|
Use Microsoft.Win32.Registry to create a Key and the same one to open it by using its CreateSubKey or OpenSubKey e.g.
Dim reg As Microsoft.Win32.Registry
Dim tmpreg As Microsoft.Win32.RegistryKey
reg.CurrentUser.CreateSubKey("Software\xx\xx\xx\")
As it returns a RegistryKey when you open it use Microsoft.Win32.RegistryKey to get the value or to set the value by using its GetValue or SetValue Properties.
Hope it helps !
AliAmjad(MCP)
First make it Run THEN make it Run Fast.
|
|
|
|
|
Thanks Ali,
But that doesn't seem to help me in solving my problem.
I wanted to find out whether 'Microsoft Office Document Imaging' has been loaded in my system, if loaded then I wanted to retrieve the path where it has been loaded. I found that if it has been loaded then we can get the path from the registry location 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrnetVersion\App Paths\mspview.exe'. mspview.exe is the Exe name to the above application and we can find the path to the exe in the sub key 'Path'.I have to search first if the key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrnetVersion\App Paths\mspview.exe' exists or not. then I have to search the sub inside it to get the path. Can you please help me out in solving this problem.
Thanks in advance.
Sekhar
|
|
|
|
|
I'm using crystal report and vb6. how can i change the connection properties of the crystal report in vb6?
In my crystal report i used stored procedure to create the report. What if i change my database name how can i change the properties in vb6 so i wouldn't change the crystal report anymore. im using ms sql server.
this is my code...
Global crxReport As CRAXDRT.Report
With crxReport.Database.Tables
For intCount = 1 To .Count
.Item(intCount).ConnectionProperties.Item("Data Source") = sServer
.Item(intCount).ConnectionProperties.Item("Initial Catalog") = sDBName_
.Item(intCount).ConnectionProperties.Item("User Id") = sUserName
.Item(intCount).ConnectionProperties.Item("password") = sPassword
Next
End With
the reports are working fine but if i change my database name it doesn't work anymore...
|
|
|
|
|
Is OOPS concept in Visual Basic 6?
Regards,
KK
Ketan K.
|
|
|
|
|
Not really. VB6 is also out of date, unsupported and rubbish. Learn VB.NET instead.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
"OOPS" is something you say when you have made a mistake.
VB6 is a procedural programming language with limited support for object oriented programming (OOP).
VB.NET on the other hand is a fully* object oriented language.
* Although some feel that it lacks certain OO features, it more than well meats the criterias for being an object oriented language.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
when i update a record in the database, the database becomes updated but the oledbdataadapter does not relect this changes until i restart the application. when I deployed the application, the changes do not even reflect even when I restart the application though the updated record appears in the database
this is the code i use to refresh the dataset.
Try
DsAsets1.Clear()
OleDbDataAdapter1.Fill(DsAsets1)
count()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
I am using Ms Access as my database.
David T. Motajo
-- modified at 12:55 Tuesday 6th November, 2007
|
|
|
|
|
Hi David
From the Above Cod, you are Clearing dataset "dsAssets1",
but Filling the dataset "DsAsets1". So check your "s" , where you will the dataset. but if this Dataset was not declared, then VS should tell you that. mybe you have many dataset and the name confused you. show us your code, if it doesnt work after you fix your Spelling Error.
Hope it Helps
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
this is the actual code am using
Try
DsAsets1.Clear()
OleDbDataAdapter1.Fill(DsAsets1)
count()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
|
|
|
|
|
hi
Did you use a wizard to create your adapter, or did create it your self, if so then lem me see the update command of your adapter.
try this and tell me your Error and remember if your table has no Primary key , you can never update the table.
Try
DsAsets1.Clear()
OleDbDataAdapter1.Fill(DsAsets1)
count()
Catch ex As OleDb.OleDbException
MsgBox(ex.Message)
End Try
End Sub
.
And Dont Forget to import the name space like this
Imports System.Data.OleDb
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
thanks. I was able to find the solution after visiting many forums.
I used this code to refresh and its now working fine
Conn.Open()
mycmd = "Select * from Asset"
da = New OleDb.OleDbDataAdapter(mycmd, Conn)
da.Fill(dsAsets1, "Asset")
Conn.Close()
I really appreciate your concern. am very grateful.Thanks again.
|
|
|
|
|
You are Welcome
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|