|
Hi, suppose that I have an Ms access database and I want to read its value from VB.NET and represent database to the form, I also want to perform the following basic action: Add new record, Update record and Delete record. Could any one give me a sample code (both for connect to the database and read/write the information from/to the database)?
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Imports System.data.oledb
Private sub ExtractData()
'connection
Dim oConn As New OleDbConnection
'command
Dim oCmd As New OleDbCommand
'dataset
Dim oDS As New DataSet
'dataadapter with command assigned
Dim oDA As New OleDbDataAdapter(oCmd)
'set connection string, you'll have to fill that bit in though
'should be easy to find if you don't know how to form it
oConn.ConnectionString = "Provider...."
oCmd.CommandType = CommandType.Text
oCmd.Connection = oConn
oCmd.CommandText = "SELECT * FROM Table1"
oDA.Fill(oDS)
'You then have a dataset to work with.
If you know SQL then you should be able to adapt that to perform all actions
Many Thanks
Harry
|
|
|
|
|
Thank you very much Harry, Now I try to adapt with your code. I will let you know when I have a problem during my development process.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
I would like to add, to have this all take care of it for you. So it'll update I would suggest using the command builder componet.
Dim cmb As New OleDbCommandBuilder
oDA.SelectCommand = cmd2
Then add your row to the dataset, or modify it's data all you have to call is.
oDA.Update(ds)
That'll take care of your updates as it automatically fills in the Update, Add, Delete command strings for you. Hope this helps as a suggestion.
Gerry
|
|
|
|
|
I have a little bit problem with ADO.NET. The reason that I have a problem is an experience with ADO from the ground. In VB6 I used to connect to database using vb6 and access database with DAO. I have used ADO for one time only with VB6 when I connect to SQL server. But it is one year ago and may be I have to check my source to make sure how it work. When I move to VB.NET I have a problem with OleDbDataAdapter and SqlDataAdapter and other component... (like DataTable, DataRow, DataSet...). I really difficult to figure out with this abstract technology. I think the only way that I should do is return to ADO and master it as soon as possible, than I might have a change to master ADO.NET in VB.Net.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
I'd say ADO.NET is much more different to ADO than ADO to DAO.
You're better off starting with ADO.NET right away if you don't need ADO.
Have a look at some MSDN articles on starting with ADO.NET, it's simple enough that you'll understand it in no time.
|
|
|
|
|
Thank you very much for your comment. Because MSDN online is very big, sometime I could not find the topic that I want. If you know the URL please provide some to me because I really want to get start ADO.NET from the first step.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Hi all,
i would like to check all the subnodes of my treeview control by clicking parent node.
(using checkbox =true)
suppose i have a treeview control with three parent node.now if i click on any parent node
the related subnodes of that parent node should be selected and if i uncheck the parent node the related subnodes will be unchecked.
i will be grateful if anyone could give me a solution or idea.
waiting for ur help.
himangshu.
|
|
|
|
|
Tri-State TreeView Control
By Ebse
http://www.codeproject.com/cs/miscctrl/TriStateTreeViewSubmissio.asp?df=100&forumid=36686&exp=0&select=779797&tid=779797
It's in C# but you can convert it here:
http://www.developerfusion.com/utilities/convertcsharptovb.aspx
|
|
|
|
|
Hi, in VB6 I could limite the user input for number only by using the KeyPress event for the text box. In VB.NET I also read about its technique to limite the user to input only number too but I forget its sample code. Could any one give me a sample code for the textbox to limite the user to input only numeric value?
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
One simple method is:
Write the following code in the keypress event of the textbox(don't forget to do the correct thing on keydown and keyup events: I do not have access to VB.NET by now, and I don't know how may it respond to my line of code, but I guess that although this code is to work, those two event MAY make it work incorrectly having no effect.)
But the code I guess should work without problem:
If SomeCondition Then e.Handled = True
And here SomeCondition is checking whether the key pressed is NOT numeric.
Please tell me if my code goes wrong.
|
|
|
|
|
Yes it is working by the concept of your code, I use the following code in my application:
If (e.KeyChar >= "0" And e.KeyChar <= "9") Or _
e.KeyChar = Chr(8) Then
e.Handled = False ' Allow the user to type number.
' e.KeyChar = Chr(8) represent for the backspace character.
Else
e.Handled = True ' No character appear in the textbox.
End If
Thank you very much.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Here all numbers and backspace[chr(8)] is allowed in this textboxfield if this code is written in its keypress event.
If (e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = Chr(8) Then
Else
e.Handled = True
End If
Dileep Devapal
|
|
|
|
|
Thank you very much for your help, now it is working.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Hello...
Im currentyl trying to create a pluginbased application that can get classes from a dll file and build a user interface from it.
Can annyone help me please, im going mad!!!
|
|
|
|
|
OK, OK!
I had done such a thing a few years ago usin VB6, listen:
(I try to explain it as simple as possible)
Create a VB6 ActiveX DLL project, as your plugin.
This plugin must have a public class (this is the class that is to be connected by your main program.)
EVERYTHING you want this plugins to do, place it in the DLL file and just for things and methods that ALL your plugins are going to do, you must expose the same interface in this class (I mean that this PUBLIC class, must be the same -have the same public methods- in all plugins) so the main program knows what to call!
Now in your main program, call each plugin by this sintax:
Set PlugIns(i)=CreateObject("PluginName.PublicClassName")
Now in your program, you can do methods of each plugin you wish easily:
Call PlugIns(i).SomeMethod()
If you have any problems or questions about what I wrote, ask and I'll explain it to you.
|
|
|
|
|
thanks for the help. but i want to get the intire class in to my application like this
in a normal application i can do like this:
i give you an exsample class:
Public Class someclass : Inherits UserControl
Friend WithEvents mybutton As Button
Public Sub New()
MyBase.new()
mybutton = New Button
mybutton.Top = 0
mybutton.Left = 0
mybutton.Height = 200
mybutton.Width = 200
Me.Controls.Add(mybutton)
End Sub
Dim mybutton As button
Private Sub mybutton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mybutton.Click
MessageBox.Show("this is a messagebox")
End Sub
and in a form i could do like this:
Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'watch the next line:
Dim myPlugin As New someclass
Me.Controls.Add(myPlugin)
myPlugin.Top = 0
myPlugin.Left = 0
myPlugin.Height = 200
myPlugin.Width = 200
End Sub
what i want to do is have the class named someclass ina seperate dll file
annybody know what i mean?
|
|
|
|
|
I have created a simple VS.NET ASPX form to collect user information. The form has several textbox inputs which the user fills in. Finally after validation clicking on a save button records the information. If I tab through the inputs when entering the info all is well. But if I press the enter key any time instead of the tab key (a common user error I would think) things screw up. Pressing the Enter key seems to re-activate Page_Load which clears the form ready for fresh user input to the whole form. How do I prevent this? Ideally it would seem best to have the Enter key performing exactly the same action as the Tab key.
Bob M
|
|
|
|
|
This question really belongs in the ASP.NET forum. But, I don't think you can do this. You definately CAN'T do it in C# or VB.NET with ASP.NET. If possible, it MUST be done using client-side JavaScript.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi
I just want to know the difference between a Class,Installer Class and Component class. And also
Difference between User Control and Custom Control
|
|
|
|
|
See Wikipedia[^] for the definition of a class. This is because it is the building block that will allow the rest of this answer to make more sense.
A Component class is a heavyweight class. It is designed to allow plugging together of the building blocks of applications more quickly. See MSDN: Component Classes[^]
An Installer Class is just a class, it is also a component, like any other class or component, that has simply inherited the ability to interact with the windows installer, so that if you create an deployment project and include an assembly with an installer class in it you can create instances of specific subtypes of the intaller class to perform customised installation actions. See MSDN: Installer class[^]
The main differences that I see between a custom control and a user control is in the trade off between power and ease-of-creation. User controls are easier to create, but have a higher overhead in order to keep them easy. Custome controls have a lower overhead but you have to write more code to get them to do what you want, but you have greater flexibility.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
hi every one i want to add file version information in the block header part of a .dll file for versioning. pls help i need it very badly
bye
|
|
|
|
|
What kind of DLL? What language and tools are you using? Is this a VS.NET Class Library? If so, it's already there. If you're asking about VB6 I'm pretty sure you just have to setup the resource.
|
|
|
|
|
Okay this is my code
txtTotal.Text = Val(txtSubtotal.Text) + Val(txtAddition.Text) + Val(txtRollaway.Text)
how do I set this to string to make the dollar sign appear
txtTotal.Text = Val(txtSubtotal.Text) + Val(txtAddition.Text) + Val(txtRollaway.Text).ToString("$#,###.00")
does not work it gives the value of 0
|
|
|
|
|
A general programming advise:
"DO NOT STICK TO ONE WAY TO WRITE YOUR CODE, IF ONE DID NOT WORK, BE SURE TO THINK FOR OTHER WAYS"
It may be because you are trying to add a String to an Integer:
Val(txtAddition.Text) Integer
+
Val(txtRollaway.Text).ToString("$#,###.00")<br /> String!!!!
but if you had not recognized it, you might have tried these other lines of code:
<br />
txtTotal.Text = "$" & ( Val(txtSubtotal.Text) + Val(txtAddition.Text) + Val(txtRollaway.Text) )<br />
<br />
'OR:<br />
<br />
txtTotal.Text = Val( Val(txtSubtotal.Text) + Val(txtAddition.Text) + Val(txtRollaway.Text) ).ToString("$#,###.00")<br />
You see, there are always lots of ways to get to a goal.
|
|
|
|