|
I am new to programming with databases. Any and all help will be very much appreciated. Thank you in advance.
I am writing an application that connects to an access database (4000 records). The database tracks boxes in a small warehouse. The box numbers are the primary key. Fields include the room number, store date, disposal date, section, shelf number.... I have successfully created a form with separate text boxes for each field. I can connect to the database and load the data into a DataSet. I can search the database by entering a box number and all of the text boxes update with the correct information. I can move forward or backwards one box at a time. The problem I am having is updating the database. Like I said, I'm new to this part of programming. I should never need to insert a line into the database, but I will most definately need to update a line. (One field is a y/n, y if the box is available for a new record.) The app will search for the first 'y' in the field and assign the user with the box number. The user will input the required info and save to the database.
Once again, I need to be able to update a line in an Access database. There is only one table.
I hope I have described this well enough to get some help. Thank you again!
Chuck
|
|
|
|
|
You need to do an Update SQL statement as following:
if you use a connection object:
con.execute "Update YourTable SET YourField= YourValue WHERE..."
if you use a database object:
db.execute "Update YourTable SET YourField= YourValue WHERE..."
Shay Noy
|
|
|
|
|
I believe I'm using a connection object. I don't really know the proper terminology. Here is a bit of my code.
Dim myConnectionString as String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=I:AccessDB.mdb"
Dim myConnection as new OleDb.OleDbConnection(myconnectionString)
---ONLOAD---
myConnection.open()
OleDbDataAdapter1.Fill(Dataset11)
And so on...
I take it this is a Connection object?
I have tried using MyConnection.execute but this doesn't work.
I'm not finding the ".execute" anywhere. Is there some Inherits that I'm missing? The only thing I'm Inherting at the moment is System.windows.forms.form
I'm sorry if I sound a little uneducated. This is the first serious application I've attempted and unfortunately my Associates in Programming probably wasn't worth the education I received. Thanks again.
|
|
|
|
|
Read up on the Update method of the OleDbDataAdapter
Steve Jowett
-------------------------
It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)
|
|
|
|
|
Hello every one
Is there any way how we can differentiate between the close click, in the control box and me.close call
My objective is...
I want the user to be able to minimize the form not to close it. When i handle it in form closing event i am not able to differentiate between me.close & lose clicked..
Regards
Nishkarsh
|
|
|
|
|
hi,
handle formClosing Event of Form which you want to minimize and write following statement
e.Cancel = True<br />
Me.WindowState = FormWindowState.Minimized
hope this helps
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
My Company
|
|
|
|
|
Thanks Rupesh
I think i have to explain the situation again
The idea was that we do not want the user to be able to close any form by clicking "Close" in control box
So we removed control box....
Now the objective is that the user should be allowed to minimize the the form..
So when we enable control box close option is also available
So i taught to handle it in form closing .... but the issue is now when i close the form from the code the same event is fired and i am not able to close the form...
Is there any way i can come over it???
I hope this will give a better understanding of my objective
Regards
Nishkarsh
|
|
|
|
|
I think the following may help you:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If e.CloseReason = CloseReason.UserClosing Then
e.Cancel = True
End If
End Sub
Shay Noy
|
|
|
|
|
I had tried this
shaynoy wrote: If e.CloseReason = CloseReason.UserClosing Then
e.Cancel = True
End If
In both the case "Me.close" and close from control box... the control come in the above condition only..
|
|
|
|
|
What about this:
Private _userClosed as Boolean = false
Public Sub SomeMethod()
_userClosed = true
Me.Close()
End Sub
Private sub Form_Closing(sender as object, e as EventArgs)
If (_userClosed) then
'-do what you want
Else
'-do what you want
End If
End Sub
Mike Lasseter
|
|
|
|
|
just use an extra variable that you set before the me.close statement then inside the form_closing event unless that variable is set.... e.cancel =true and exit sub
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
You can also disable the close button of the form:
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As IntPtr, ByVal nPosition As Integer, ByVal wFlags As Long) As IntPtr
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As IntPtr) As Integer
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As IntPtr) As Boolean
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Private Const MF_DISABLED = &H2
Public Sub DisableCloseButton(ByVal hwnd As IntPtr)
Dim hMenu As IntPtr
Dim menuItemCount As Integer
hMenu = GetSystemMenu(hwnd, False)
menuItemCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, menuItemCount - 1, MF_DISABLED Or MF_BYPOSITION)
Call RemoveMenu(hMenu, menuItemCount - 2, MF_DISABLED Or MF_BYPOSITION)
Call DrawMenuBar(hwnd)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DisableCloseButton(Handle)
End Sub
Shay Noy
|
|
|
|
|
|
Hi I am trying to make live Broadcast program using video cam which is attached to my laptop. I am relatvely new to this windows Media Encoder SDK. I found on the net this can be use to make the live broadcast program. Is there anyone familiar with those technology? Thanks a million
|
|
|
|
|
Do a seach on CodeProject for web cam. That might be able to help you.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
As part of a presentation software, I decided to write a custom control that provides cool text effects (like in powerpoint 2007). To support transparency, I used Bob Powell's code. Everything is fine in the designer, but when I try to animate the control, it flickers a lot. Double buffering just gives it a black background. Can anyone help me remove the flicker?
The code for the class:
Imports System.Drawing.Drawing2D
Public Class Text2007
Inherits System.Windows.Forms.UserControl
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20
Return cp
End Get
End Property
Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
End Sub
Protected Sub InvalidateEx()
If (Parent Is Nothing) Then
Exit Sub
Else
Dim rc As New Rectangle(Location, Size)
Parent.Invalidate(rc, True)
End If
End Sub
Protected Overrides Sub OnMove(ByVal e As EventArgs)
Me.InvalidateEx()
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim bm As New Bitmap(CInt(Me.ClientSize.Width / 5), CInt(Me.ClientSize.Height / 5))
Dim pth As New GraphicsPath()
pth.AddString(Me.Text, New FontFamily("Verdana"), CInt(FontStyle.Regular), 100, New Point(20, 20), StringFormat.GenericTypographic)
Dim h As Graphics = Graphics.FromImage(bm)
Dim mx As New Matrix(1.0F / 5, 0, 0, 1.0F / 5, -(1.0F / 5), -(1.0F / 5))
h.SmoothingMode = SmoothingMode.AntiAlias
h.Transform = mx
Dim p As New Pen(Color.Yellow, 3)
h.DrawPath(p, pth)
h.FillPath(Brushes.Yellow, pth)
h.Dispose()
e.Graphics.Transform = New Matrix(1, 0, 0, 1, 50, 50)
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic
e.Graphics.DrawImage(bm, ClientRectangle, 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel)
e.Graphics.FillPath(Brushes.Black, pth)
pth.Dispose()
End Sub
Public Sub pInvalidate()
Me.InvalidateEx()
End Sub
End Class
~ Soumya92
|
|
|
|
|
Hi,
I want to open files (such as .xls, .htm, .pdf)
in the VB 6.0 page.
Can any one please help me.
Ranjan
|
|
|
|
|
try to use the ole object
Shay Noy
|
|
|
|
|
while i try to insert row by
Sheet.Rows.Insert(Shift:=Excel.XlDirection.xlDown) i get error is
To prevent possible loss of data, Microsoft Office Excel cannot shift nonblank cells off the worksheet.
Try to locate the last nonblank cell by pressing CTRL+END, and delete or clear all in cells between the last cell and the end of your data. Then select cell A1 and save your workbook to reset the last cell used.
Or, you can move the data to a new location and try again.
so please help me how insert row
Hitesh sojitra
|
|
|
|
|
hitesh sojitra wrote: while i try to insert row by
Sheet.Rows.Insert(Shift:=Excel.XlDirection.xlDown)
This is because you have not selected/told excel where to insert new Row. It should be something like this.
Sheet1.Rows("1:1").Insert Shift:=Excel.XlDirection.xlDown
The code above will add new row before cell A1 so everything in row 1 will move to row 2.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
Thanks a lot it's working
Hitesh sojitra
|
|
|
|
|
one more quiry please
if i wants insert 3 row after A5 than it is (5:3) ? or any thing else?
Hitesh sojitra
|
|
|
|
|
thanks i got it..............
Hitesh sojitra
|
|
|
|
|
hi
i am using data binding and this is my code
Imports System.Drawing.Printing<br />
<br />
<br />
Public Class Form2<br />
Public ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _<br />
"Data Source =" & Application.StartupPath & "\ITDSS.mdb"<br />
Public con As New OleDbConnection(ConStr)<br />
Dim DataSet1, course As New DataSet<br />
'Dim SQLstr = "SELECT SectionID,Type,Group,TeacherID from [Section]"<br />
Dim SQLstr = "SELECT DISTINCT s.LevelNo, c.CourseID,c.SectionID,c.Type,c.Group, r.RoomID FROM [Section] c,Course s,[Slot] r where s.CourseID=c.CourseID and c.SectionID=r.SectionID ORDER BY s.LevelNo" ' in(select CourseID from Course Where LevelNo=1)" 's,Course c WHERE s.CourseID = c.CourseID ORDER BY c.LevelNo"<br />
<br />
Dim DataAdapter1 As New OleDb.OleDbDataAdapter(SQLstr, con)<br />
<br />
'----------------------===============================<br />
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Dim SQLstr, SQLstr1 As String<br />
<br />
'Dim DataSet1, course As New DataSet<br />
'SQLstr = "SELECT SectionID,Type,Group from [Section]"<br />
Con.Open()<br />
<br />
'DataAdapter1 = New OleDb.OleDbDataAdapter(SQLstr, con)<br />
<br />
<br />
DataAdapter1.Fill(DataSet1, "Section")<br />
<br />
Me.DataBindings.Add("text", DataSet1, "Section.SectionID")<br />
<br />
DataGridView1.DataSource = DataSet1<br />
DataGridView1.DataMember = "Section"<br />
<br />
<br />
Dim bmb As BindingManagerBase<br />
bmb = Me.BindingContext(DataSet1, "Section")<br />
bmb.Position = bmb.Count<br />
bmb.Position = 0<br />
end sub
and i want to update it when button press
i but the flowing code
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click<br />
Dim CmdB As New OleDb.OleDbCommandBuilder(DataAdapter1)<br />
DataAdapter1.Update(DataSet1, "Section")<br />
<br />
End Sub<br />
End Class
but it give error update statement
please i need help
|
|
|
|
|
Um where is your update script!, I can see your select but no update
Never underestimate the power of human stupidity
RAH
|
|
|
|