|
i am usind dataadapter and dataset objects to bind some data from the database in the textbox control. the code i m using is as follows:
textbox1.databindigs.add("text",dataset.tables(0),"Name")
This code is able to retrieve the field 'Name' from the database and puts it in this textbox. Now i want that if some change is made in this textbox,then that should be updated to the database table as well. for this purpose i m using dataset.acceptchange method. But this is not giving result. please guide me in this..
thanks..
-- modified at 14:42 Monday 19th March, 2007
|
|
|
|
|
manni_n wrote: the code i m using is as follows:
textbox1.databindigs.add("text",dataset.tables(0),"Name")
This code just sets up a single databinding and it's not even the code you used. Copy and Paste the REAL code you're using. Do not retype the code yourself! What's the code that's filling the DataSet your binding to? What does the code look like where you're writing the DataSet back to the database?
manni_n wrote: for this purpose i m using dataset.acceptchange method
Do you know what AcceptChanges does?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Try<br />
Dim da As New OleDbDataAdapter("select * from dbo_info where IDNo='" & Label2.Text & "' ", "provider=microsoft.jet.oledb.4.0;data source=e:\new folder\testIP.mdb;")<br />
Dim ds As New DataSet<br />
da.Fill(ds)<br />
Label2.DataBindings.Add("text", ds.Tables(0), "IDNo")<br />
Label43.DataBindings.Add("text", ds.Tables(0), "Name")<br />
Label42.DataBindings.Add("text", ds.Tables(0), "ParName")
i am using this code to bind the text box ... imean i am able to retrieve the data in the database now i want if something is changed in that textbox then that change should be updated in same data base..
i want to use dataset acceptchange method ....
i dont have that much knowledge in this coding...
please tell me the way to do this....
method other than dataset accept is also welcome....just i want to solve my purpose
thanks....
|
|
|
|
|
You don't have any code to write the dataset changes back to the database. You can use the same dataadapter object that you use to populate the dataset, but you have to give it the SqlCommands to make the Insert, Update, and Delete changes to the actual database. You can either do this by hand or, if you're old using a single table in your SELECT query, you can use the OleDbCOmmandBuilder class to make the other thre queries for you.
You could modify your code like this:
Dim da As New OleDbDataAdapter("select * from dbo_info where IDNo='" & Label2.Text & "' ", _
"provider=microsoft.jet.oledb.4.0;data source=e:\new folder\testIP.mdb;")
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(myDataAdapter)
Dim ds As New DataSet
da.Fill(ds)
You'd probably also want to make the DataSet and DataAdapter class-scope so you can use it from something like a "Submit" button.
When you want to save the changes back to the database:
da.Update(ds)
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
you have initialized cb but havnt used anywhere....
whats the use of cb in this coding....?
|
|
|
|
|
You don't do anything with it.
Read up on the OleDbCommandBuilder class here[^].
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello!
I want to syncronize between two SQL 2005 databases. I'm quit new at this.
I want to have a maste database where I do all changes. The slave database i supposed to connect to the Master database and syncronice onec per day.
Can I write a application that triggers this or how can I make it work?
Thanks for all help!
Best regards Richard Segerlund
|
|
|
|
|
You wouldn't normally do this with any VB.NET code at all. This is something that you'd do with Replication Services[^] built into SQL Server.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks for your help. I will read and see what I can find.
Best regards Richard Segerlund
|
|
|
|
|
Ho do i remove this attribute xmlns="" (blank namespace) from my XMLDocument
-- modified at 10:56 Monday 19th March, 2007
|
|
|
|
|
Hi Tomlinson,
Your question is a bit vague (the structure of xml documents is not standardized, the way for example EDI is), so I'll make a few assumptions:
- you need to process xml documents from a single source, on a regular basis
- the documents are created by another party, and you have no say over their structure
- the structure of the documents is constant
- you only need the content of the document and are able to read it into a recordset/datatable/dataset.
If so, then I advise you to read the content into a dataset, using your own xml schema.
If not so:
- why do you want to remove this attribute? In other words, how is this attribute bothering you?
- who creates the xml documents to begin with?
- do you need to process many similar documents, many dissimilar documents, or only a single document?
regards,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi,
I'm using VB.NET 2005 Express, and I'm working with an XML file, which populates a DataSet, DataTable and DataGridView. An amazing achievement for somebody of my current skill set!!
The way my app works at the moment, there is a possibility that I could end up with duplicate entries in my XML file, so I was thinking of running an SQL statement to remove any duplicates.
Everything I've found so far seems to suggest that I need to use an adapter and a connection in order to be able to run an SQL statement. OK - but this doesn't seem right to me.
If it IS correct, it seems that I'd have to create the adapter and a connection AFTER I've read in all my data (ReadXML) - which seems odd.
Perhaps I'm just over-complicating my problem???
Any advice would be really appreciated.
|
|
|
|
|
It sounds to me like you're over complicating the problem. You'd do better to just check for a node before you add it, don't add it if it exists. Solve the underlying problem instead of trying to fix it later.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks for your reply. Your advice is good.
My project is an Exchange Rate application which is importing 200 rows of data from a Word document. At the moment, I'm just reading it in from Word, reading in my XML file, adding the new rows to the existing table, and writing my XML file containing everything.
With your suggestion, am I right in thinking that I'd need to sort my DataTable so that when I come to add my new row, I've got all my countries sorted so that they're together, and it only has to work with a few rows to determine if the data already exists?
Meanwhile, I'd still like to know (for future reference) whether I need an adapter/connection to run SQL statements.
|
|
|
|
|
If you have XML, you can use SelectSingleNode on an Xmldocument to see if you r node existss.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Been coding for about 3 months now and am currently making a "login" client for myself. I hve created a streamreader and have linked it to a .txt file which is located on my hardrive and i am struggling to get it to read of multiple lines so i can have more than one user. This is the code i have at the moment
Public Class Form1<br />
Dim webe As New ProcessStartInfo()<br />
Dim username1 As New IO.StreamReader("C:\Textfile.txt")<br />
<br />
Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click<br />
If Username.Text & Password.Text = username1.ReadToEnd & "lol" Or Username.Text & Password.Text = "Admin" & "admin" Then<br />
StatusStrip.Text = "Welcome " & Username.Text
Thanks In Advance
|
|
|
|
|
Text file suppose to have more than one record there fore you should read the values inside a loop. Please see example below. The shown code sample below suppse to be inside Login_Click procedure
Dim webe As New ProcessStartInfo()
Dim username1 As New IO.StreamReader("C:\Textfile.txt")
Do While NOT UserName.EndOfStream
If UserName1.ReadLine() = UserName.Text.toString & PassWord.Text.ToString Then
'login information exist perform some type of actions
exit do
ElseIf UserName.Text & PassWord.Text = "Admin" & "admin" Then
StatusStrip.text = "WelCome" & userName.Text
End IF
Loop
UserName1.Close()
-- modified at 12:28 Monday 19th March, 2007
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
I added in your code and i seen to be getting this error under the "Username.EndOfReader" 'EndofReader is not a members of the windows.form.textbox'
Another expection i am getting is the "exit loop" is thrwoing an exception, 'exit must be followed by sub, function, property etc etc etc'
I have tried to play about with it but still struggling with working it out.
|
|
|
|
|
Sorry my mistake... Convert .text.toString and then use exit do also Replace EndOfReader with EndOfStream... I apologize...
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
|
JUNETY or anyone else, i have just had to format my pc and when i load up VS05 and my code i keep getting this error when debuging it, i have looked everywhere but it is really baffling me! any help will be appreciated!
Dim username1 As New IO.StreamReader("C:\username.txt")<br />
Dim password1 As New IO.StreamReader("C:\password.txt")<br />
Dim adminun As New IO.StreamReader("C:\adminun.txt")<br />
Dim adminpw As New IO.StreamReader("C:\adminpw.txt")<br />
<br />
<br />
Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click<br />
Do While username1.EndOfStream<br />
If username1.ReadLine() = Username.Text.ToString & Password.Text.ToString Then<br />
Exit Do<br />
End If<br />
Loop<br />
username1.Close()<br />
Do While password1.EndOfStream<br />
If username1.ReadLine() = Username.Text.ToString & Password.Text.ToString Then<br />
Exit Do<br />
End If<br />
Loop<br />
password1.Close()<br />
End Sub<br />
ERROR:
System.ObjectDisposedException was unhandled<br />
Message="Cannot read from a closed TextReader."<br />
ObjectName=""<br />
Source="mscorlib"<br />
StackTrace:<br />
at System.IO.__Error.ReaderClosed()<br />
at System.IO.StreamReader.get_EndOfStream()<br />
at WindowsApplication1.Form1.Login_Click(Object sender, EventArgs e) in C:\Users\Brad\Documents\Visual Studio 2005\Projects\SC Login\SC Login\Form1.vb:line 9<br />
at System.Windows.Forms.Control.OnClick(EventArgs e)<br />
at System.Windows.Forms.Button.OnClick(EventArgs e)<br />
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)<br />
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)<br />
at System.Windows.Forms.Control.WndProc(Message& m)<br />
at System.Windows.Forms.ButtonBase.WndProc(Message& m)<br />
at System.Windows.Forms.Button.WndProc(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br />
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br />
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)<br />
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)<br />
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)<br />
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)<br />
at System.Windows.Forms.Application.Run(ApplicationContext context)<br />
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()<br />
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()<br />
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)<br />
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81<br />
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)<br />
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br />
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br />
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br />
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br />
at System.Threading.ThreadHelper.ThreadStart()
I am on Vista but still cannot see why it is thwoing this exception, I have tried putting the files on desktop etc but still getting "Cannot read from a closed TextReader". Also another problem is that when i click "login" once nothing happens even with other code but when i double click i get the above error!
Thanks
-- modified at 20:36 Tuesday 20th March, 2007
|
|
|
|
|
Because you are making a mistake as follows:
When you close the first stream therefore without reopening it you can't define UserName1 inside the second stream because its closed. Your approach to check username, password, etc. seems not appripriate. I suggest you to reorganize your code.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Hello!
Here is my function which opens a XML document and retrieves the value of it. But I am getting an error message because of a null value. It doesn't read the DateInstalled value from the file. What is the error? Thanks.
Private Function GetConfigParameter(ByVal MyKey As String) As String
Dim XmlDocument As New XmlDocument
Dim XmlNode As XmlNode = Nothing
XmlDocument.Load(Environment.CurrentDirectory & "\app.con")
XmlNode = XmlDocument.DocumentElement.SelectSingleNode("//configuration/AppDefaultValues/add[@key=""" & MyKey & """]")
GetConfigParameter = XmlNode.Attributes.GetNamedItem("value").Value
XmlDocument = Nothing
End Function
-- modified at 12:02 Monday 19th March, 2007
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Are you talking about AppSettings ?
here is a link[^]
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
No! actually it is an simple xml file residing under current directory. Somehow it is not opening file and getting the values. I haven't figured out yet what is causing the problem.
Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|