|
Hi,
I haveadded a database using the wizard in vb express 2005, now I am able to add, delete, jump to records etc as a standard, however when I close my application then open itagain, the new data previously entered is lost.
I believe this has something to do with my altering the dataset and not the actual database, All i need i think is to click on the save button, which will then save the new data entered into the database, how do I do this?
Could anyone help, or guide me to a good tutorial where i could potentially pick up code?
Thanks in advance
Jaidev
|
|
|
|
|
All you have to do is call the .Update() method on your data adapter. An example would be something like:
Private Sub SaveButton_Click(blah, blah) Handles SaveButton.Click
myDataAdapt.AcceptChangesDuringUpdate = True
myDataAdapt.Update()
End Sub
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi,
Thanks for your reply,
the AcceptChangesDuringUpdate method doesnt seem to exist. also the "myDataAdapt" I'm imagining i'd have to declare this first as a new data adpater?
do i require a data set?
Also do i need to do work anywere apart from onthe save button? the database is quiet simple, ive used the wizard to call adatabase from the computer. it's an Access Database, therefore i am not using SQL.
Thanks
|
|
|
|
|
OK. I would suggest picking up a book on VB.NET and/or ADO.NET. Using the wizards for all of your data access just makes your code impossible to support since YOU don't know where the designer put any of the code that you need to change to get it to do what you want. Just about noone who does this for a living uses the wizards because they cranks out code that just needs to be completely overhauled anyway.
jady84 wrote: the AcceptChangesDuringUpdate method doesnt seem to exist
This means that you're using the .NET Framework 1.x and VB.NET 2002/2003. That property doesn't exist in .NET 1.x.
jady84 wrote: also the "myDataAdapt" I'm imagining i'd have to declare this first as a new data adpater?
No. You use the existing DataAdapter that was created in your code to load the data from the database. Where is that? I have no idea. The wizard put the code somewhere, I just can't tell you where.
jady84 wrote: do i require a data set?
You already have one. The DataGrid is showing you the data that's in it. This is where all the changes to the data are going. The problem is you have to call the Update method on the DataAdapter that filled the DataSet object.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi
I want that when my program begins, the form1 which loads onto the screen opens in maximized, therefore the three icons on the top right hand corner should only have close, minimize and restore down.
I'm assuming this should be an easy task, how do I do it?
Thanks in advance
Jaidev
|
|
|
|
|
Set the windowstate of the form to maximized when the form is loading.
Like:
Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
me.WindowState = FormWindowState.Maximized
End Sub
The rest takes care of itself.
Mike Lasseter
|
|
|
|
|
thnx
Ahmed El-Badry
|
|
|
|
|
each one of those are a property which you can access in either code or the property window.
windowstate - minmize/normal/maximize
minimizebox - whether the form can be minimized
maximizebox - whehter the form cna be maximized
|
|
|
|
|
vb.net
i posted this one already some time ago, but with no success.
when altering a table i use the sql-string
<br />
ALTER TABLE MyTable ADD columnname FLOAT<br />
but my columnname consists of two words ( firstname, familyname).
so i use this command:
<br />
Cmd1.CommandText="ALTER TABLE MyTable ADD 'max powers' FLOAT"<br />
but now the name appears like this in the new column header: 'max powers'
how can i create the new column without '-character?
|
|
|
|
|
Although supported, you shouldn't be giving columns names with spaces in them. If you want the name to show up in the header change the header text in your UI, not in the SQL table.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Apostrophes are not used to specify a name in a query. You use something like brackets [] or grave accents ``, depending on what database you are using.
You failed to mention what database you are using...
---
Year happy = new Year(2007);
|
|
|
|
|
sorry, i am trying to insert a new column to an excel table. i know, that i shouldn't use names with space in them, but in this case it is necessary. i need to insert firstname and family name to the table, cause i want to export results of a workink time analysis to this table to allow the user to do further processing with those dates. i also tried to use automation to export data to excel, but with no success.
|
|
|
|
|
Access uses brackets to specify a name, so my guess is that Excel does to. Try this:
ALTER TABLE MyTable ADD [max powers] FLOAT
---
Year happy = new Year(2007);
|
|
|
|
|
ok, thanks very much, i will try.
|
|
|
|
|
having a map
i want to point locations on that map when clicking on it
so i thought of creating a label and setting the location of that label same as the location of the mouse click event
so far so good,
but the prob is that : i want to point to more then 1 location
so any hint of how can i create as many labels as i clicked on the map?with location of the labels as location of the mouse clicked?
this is what i used till now
Private Sub Form2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick<br />
<br />
Me.Label1.Location = New System.Drawing.Point(e.Location.X, e.Location.Y)<br />
Me.Label1.Visible = True<br />
end sub
if there is any other hint let me know plz
thx
Regards
Ramy
|
|
|
|
|
You need to dynamically create the label in the function. Somthing along the lines of:
<br />
Dim lbl As New Label<br />
<br />
lbl.Location = New System.Drawing.Point(100, 100)<br />
lbl.Text = "This is a test"<br />
lbl.Visible = True<br />
Me.Controls.Add(lbl)<br />
Mike Lasseter
|
|
|
|
|
thx it worked
i forgot to add : Me.Controls.Add(lbl)
-----
i want to ask another thing ,after adding these labels...how can i click on each lables ?
i mean when i click on label do action ... ex : msgbox("hello")
Regards
Ramy
|
|
|
|
|
<br />
Public Sub AddLabel()<br />
Dim lbl As New Label<br />
<br />
lbl.Location = New System.Drawing.Point(100, 100)<br />
lbl.Text = "This is a test"<br />
lbl.Visible = True<br />
Me.Controls.Add(lbl)<br />
AddHandler lbl.Click, AddressOf Label_Click<br />
End Sub<br />
<br />
Private Sub Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) <br />
MessageBox.Show("this is a test")<br />
<br />
'You can remove the handler like so if necessary<br />
Dim lbl As Label = DirectCast(sender, Label)<br />
RemoveHandler lbl.Click, AddressOf Label_Click<br />
End Sub<br />
I noticed that you are using suggesting using msgbox. You really should avoid using this since it is in the Microsoft.VisualBasic namespace which allows the legacy commands to work. You should use the .Net commands when possible.
Mike Lasseter
|
|
|
|
|
so far so good... thx
before i thought about the ideas of adding labels
i thought of doing the following :
FillEllipse(m_brush, 0, 0, m_width, m_height)
and everything went good.
but i couldnt click on each added ellipse any hint for that (like the idea of the labels)
AddHandler lbl.Click, AddressOf Label_Click
is there a way like : AddHandler ellipse.click ??
Regards
Ramy
|
|
|
|
|
Since the ellispe is not a control it will not support events. The only way I can think of with an ellipse is to keep track of the ellipses you have created and the area they cover. Then in your click event you can see if the mouse click was in the area of the ellispe. Then you will perform what ever action you want.
Other than that you could create your own user control. There are plenty of examples for this if you use google.
Mike Lasseter
|
|
|
|
|
lets get back to the idea of creating labels.
lets suppose 1 i created 10labels,how can each lable perform different action ?
Regards
Ramy
|
|
|
|
|
You can store what type of label it is in the tag property. Then in your click event handler you can do cast the sender (the sender will be the label that was clicked) as a label then access its tag property. Based on its tag property you can perform your desired actions.
Mike Lasseter
|
|
|
|
|
kindly,
can u help me with this issue ?
mr_lasseter wrote: You can store what type of label it is in the tag property
because i m new with this Tag thing..Thank you
Regards
Ramy
|
|
|
|
|
Public Sub AddLabel()
Dim lbl As New Label
lbl.Location = New System.Drawing.Point(100, 100)
lbl.Text = "This is a test"
lbl.Visible = True
'isCity & isState are made up values
if isCity then
lbl.Tag = 1
elseif isState then
lbl.Tag = 2
end if
Me.Controls.Add(lbl)
AddHandler lbl.Click, AddressOf Label_Click
End Sub
Private Sub Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim lbl as Label = DirectCast(sender, Label)
if lbl.Tag = 1 then
messagebox.show("You clicked a city")
elseif lbl.Tag = 2 then
messagebox.show("You clicked a state")
end if
End Sub
Mike Lasseter
|
|
|
|
|
How would i code a loop to go through a listbox and take each value out of it to insert the values into textboxes?
Would i use a loop?
Dim strLan As String
strLan = lstX.SelectedIndex() = 0
txtX.Text = strLan
This code isnt working for me, somthing pretty damn basic i know!
|
|
|
|