|
Dear you are really special to me and you have made good experience in vb.net windows application. I am a beginner. I have a problem to update Database Record from in my Windows application. Hope you may help me.
My source table has more than one column have primary key (composite primary key) if I have only one Column set as Primary Key I can update and Delete Database Record.
But My Database table using 4 columns as Primary Key how to validate the primary key while checking the record is exist? In Where condition?
I write the code below. Pleas help me to solve my small Problem and you will be appreciated.
Thanking you.
Private Sub Cmd_Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Cmd_Save.Click
Dim sql As String
sql = " Select * From ICECREAM_TRANSACTIONS order by Ice_Seq"
Dim Adp_1 As New OleDb.OleDbDataAdapter(sql, Cn_Def)
If Status Then
If Trim(Me.Comb_IDMASTER.Text) <> Nothing AndAlso IsNumeric(Me.Comb_IDMASTER.Text) Then
If Trim(Me.Cmb_Fish_Code.Text) <> Nothing AndAlso IsNumeric(Me.Cmb_ice_Code.Text) Then
If Trim(Me.DTP_icecream_DATMASTER.Text) <> Nothing AndAlso IsDate(Me.DTP_icecream_DATMASTER.Text) Then
If Trim(Me.CMB_MKT_CODEMASTER.Text) <> Nothing AndAlso IsNumeric(Me.CMB_MKT_CODEMASTER.Text) Then
If Not Found_Prim("ICECREAM_TRANSACTIONS", "ICE_SEQ", " & Val(Me.Comb_IDMASTER.Text) & " And "ICE_CODE", "& Val(Me.Cmb_Ice_Code.Text) & " And "ICETRN_DAT", "Me.DTP_ICETRN_DATMASTER.Text" And "MKT_CODE", "& Val(Me.CMB_MKT_CODEMASTER.Text)&") Then
CMDS.Exec(Cn_Def, "Insert into ICECREAM_TRANSACTIONS(Ice_Seq,Ice_Code,ICETRN_DAT,MKT_CODE,QTY,WHOLSALE_PRICE,RETAIL_PRICE,NATURE,EXPORT,IMPORT) Values(?,?,?,?,?,?,?,?,?,?)", _
New Object() {Val(Me.Comb_IDMASTER.Text), Val(Me.Cmb_Ice_Code.Text), Me.DTP_ICETRN_DATMASTER.Text, Val(Me.CMB_MKT_CODEMASTER.Text), Val(Me.Txt_QTY.Text), Val(Me.Txt_WHOLSALE_PRICE.Text), Val(Me.Txt_RETAIL_PRICE.Text), Me.TXT_NATURE.Text, Me.CHK_EXPORT.Checked, Me.CHK_IMPORTED.Checked})
MsgBox("New Record Added into the Database " & vbCrLf & "___________" & vbCrLf & vbCrLf & "Insert a New Record", MsgBoxStyle.Information, Me.Text)
Clear_Txt()
Else
CMDS.Exec(Cn_Def, "Update ICE_TRANSACTIONS set ICE_SEQ=?,ICE_CODE=?,ICETRN_DAT=?,MKT_CODE=?,QTY=?,WHOLESALE_PRICE=?,RETAIL_PRICE=?,TOTAL_PRICE=?,NATURE=?,EXPORT=?,IMPORT=? Where ICE_SEQ=" & Me.Comb_ICE_SEQ.Text& "AND ICE_CODE = " & Me.Cmb_Ice_Code.Text &" AND ICETRN_DAT= "& Me.DTP_ICETRN_DAT.Text &" AND MKT_CODE = "& Me.CMB_MKT_CODEMASTER.Tex&" 'New Object() {Me.Comb_ICE_SEQ.Text, Me.Cmb_ICE_Code.Text, Me.DTP_ICETRN_DAT.Text, Me.Txt_MKT_CODE.Text, Val(Me.Txt_QTY.Text), Val(Me.Txt_WHOLSALE_PRICE.Text), Val(Me.Txt_RETAIL_PRICE.Text), Me.TXT_NATURE.Text, Me.CHK_EXPORT.Checked, Me.CHK_IMPORTED.Checked})
Cmd_Cancle_Click(sender, e)
End If
End If
End If
End If
End If
Else
End Sub
Rameel Rahim India
|
|
|
|
|
I got the class CalendarColumn which create DateTimePicker cell in GridView from MSDN.
I try to modify this class to allow user choose ShowCheckBox in DateTimePicker or not but I am fail.
Please help me the way to add this property which allow user choose to display CheckBox in DateTimePicker or not.
Thanks so much!
This is the class CalendarColumn :
Imports System
Imports System.Windows.Forms
Public Class CalendarColumn
Inherits DataGridViewColumn
Public Sub New()
MyBase.New(New CalendarCell())
End Sub
Public Overrides Property CellTemplate() As DataGridViewCell
Get
Return MyBase.CellTemplate
End Get
Set(ByVal value As DataGridViewCell)
' Ensure that the cell used for the template is a CalendarCell.
If (value IsNot Nothing) AndAlso _
Not value.GetType().IsAssignableFrom(GetType(CalendarCell)) _
Then
Throw New InvalidCastException("Must be a CalendarCell")
End If
MyBase.CellTemplate = value
End Set
End Property
End Class
Public Class CalendarCell
Inherits DataGridViewTextBoxCell
Public Sub New()
' Use the short date format.
Me.Style.Format = "d"
End Sub
Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _
ByVal initialFormattedValue As Object, _
ByVal dataGridViewCellStyle As DataGridViewCellStyle)
' Set the value of the editing control to the current cell value.
MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, _
dataGridViewCellStyle)
Dim ctl As CalendarEditingControl = _
CType(DataGridView.EditingControl, CalendarEditingControl)
ctl.Value = CType(Me.Value, DateTime)
End Sub
Public Overrides ReadOnly Property EditType() As Type
Get
' Return the type of the editing contol that CalendarCell uses.
Return GetType(CalendarEditingControl)
End Get
End Property
Public Overrides ReadOnly Property ValueType() As Type
Get
' Return the type of the value that CalendarCell contains.
Return GetType(DateTime)
End Get
End Property
Public Overrides ReadOnly Property DefaultNewRowValue() As Object
Get
' Use the current date and time as the default value.
Return DateTime.Now
End Get
End Property
End Class
Class CalendarEditingControl
Inherits DateTimePicker
Implements IDataGridViewEditingControl
Private dataGridViewControl As DataGridView
Private valueIsChanged As Boolean = False
Private rowIndexNum As Integer
Public Sub New()
Me.Format = DateTimePickerFormat.Short
End Sub
Public Property EditingControlFormattedValue() As Object _
Implements IDataGridViewEditingControl.EditingControlFormattedValue
Get
Return Me.Value.ToShortDateString()
End Get
Set(ByVal value As Object)
If TypeOf value Is String Then
Me.Value = DateTime.Parse(CStr(value))
End If
End Set
End Property
Public Function GetEditingControlFormattedValue(ByVal context _
As DataGridViewDataErrorContexts) As Object _
Implements IDataGridViewEditingControl.GetEditingControlFormattedValue
Return Me.Value.ToShortDateString()
End Function
Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As _
DataGridViewCellStyle) _
Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl
Me.Font = dataGridViewCellStyle.Font
Me.CalendarForeColor = dataGridViewCellStyle.ForeColor
Me.CalendarMonthBackground = dataGridViewCellStyle.BackColor
End Sub
Public Property EditingControlRowIndex() As Integer _
Implements IDataGridViewEditingControl.EditingControlRowIndex
Get
Return rowIndexNum
End Get
Set(ByVal value As Integer)
rowIndexNum = value
End Set
End Property
Public Function EditingControlWantsInputKey(ByVal key As Keys, _
ByVal dataGridViewWantsInputKey As Boolean) As Boolean _
Implements IDataGridViewEditingControl.EditingControlWantsInputKey
' Let the DateTimePicker handle the keys listed.
Select Case key And Keys.KeyCode
Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, _
Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp
Return True
Case Else
Return False
End Select
End Function
Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) _
Implements IDataGridViewEditingControl.PrepareEditingControlForEdit
' No preparation needs to be done.
End Sub
Public ReadOnly Property RepositionEditingControlOnValueChange() _
As Boolean Implements _
IDataGridViewEditingControl.RepositionEditingControlOnValueChange
Get
Return False
End Get
End Property
Public Property EditingControlDataGridView() As DataGridView _
Implements IDataGridViewEditingControl.EditingControlDataGridView
Get
Return dataGridViewControl
End Get
Set(ByVal value As DataGridView)
dataGridViewControl = value
End Set
End Property
Public Property EditingControlValueChanged() As Boolean _
Implements IDataGridViewEditingControl.EditingControlValueChanged
Get
Return valueIsChanged
End Get
Set(ByVal value As Boolean)
valueIsChanged = value
End Set
End Property
Public ReadOnly Property EditingControlCursor() As Cursor _
Implements IDataGridViewEditingControl.EditingPanelCursor
Get
Return MyBase.Cursor
End Get
End Property
Protected Overrides Sub OnValueChanged(ByVal eventargs As EventArgs)
' Notify the DataGridView that the contents of the cell have changed.
valueIsChanged = True
Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
MyBase.OnValueChanged(eventargs)
End Sub
End Class
Public Class Form1
Inherits Form
Private dataGridView1 As New DataGridView()
<stathreadattribute()> _
Public Shared Sub Main()
Application.Run(New Form1())
End Sub
Public Sub New()
Me.dataGridView1.Dock = DockStyle.Fill
Me.Controls.Add(Me.dataGridView1)
Me.Text = "DataGridView calendar column demo"
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles Me.Load
Dim col As New CalendarColumn()
'I wish the code : col.ShowCheckBox = true / false here
Me.dataGridView1.Columns.Add(col)
Me.dataGridView1.RowCount = 5
Dim row As DataGridViewRow
For Each row In Me.dataGridView1.Rows
row.Cells(0).Value = DateTime.Now
Next row
End Sub
End Class
|
|
|
|
|
u will take the dll of datetime picker
put the datagridview1 in the toolbox and drop in the form
right click of addcolumn then there are three field (1)Name (2) Type (3) header text
in name write the column name , type select the type of dll ,write the name of the header
|
|
|
|
|
Thanks rohitsrivastava !
I think that is a solution.
I will test for this.
But how about coding to modify the class.
Best regards,
pvphuc
|
|
|
|
|
My VB 6 MDI project isn't closing right. When I hit the red X, it doesn't terminate, and when compiled, it doesn't close the program when you hit the X. What am I missing? Is there a quick way to close all windows and processes associated with a project and make sure everything is terminated properly?
Thanks for your help.
"Go to, I’ll no more on’t; it hath made me mad." - Hamlet
|
|
|
|
|
The best way to terminate your program is to catch Form Closing event & if button click. In Form Closing, add the following lines:
<object instances=""> = nothing
Me.Dispose()
GC.Collect()
Make sure that you make all of the objects created as Nothing, and then call Me.Dispose. For eg.,
Dim myDataGrid as DataGrid
Dim obj as Object
....
in Form Closing
myDataGrid = Nothing
obj = Nothing
This will make all the objects used as Null & free up all the memory. To remove all such object permanently, it is recommended to use GC.Collect(). GC frees all vars. as Nothing or not used from the memory. This is an Object Oriented concept.
Hope this helps.
Thanks
Terry
|
|
|
|
|
Thanks for your help, but I need the answer for VB6. Does it work the same way?
"Go to, I’ll no more on’t; it hath made me mad." - Hamlet
|
|
|
|
|
I believe it will work. 99% GC line wont work. Stil, I m not sure. Check out. If it gives error, remove it & try. Rest all remains the same.
Thanks
Terry
|
|
|
|
|
The MDI form's QueryUnload method probably has something that prevents your form from closing...
|
|
|
|
|
For anyone else having this problem, I found this article very helpful:
http://vbcity.com/forums/topic.asp?tid=99480[^]
The problem was, I wasn't unloading the child forms last. I was running code after the unload was called. The code reloaded them, and then the parent form ended with them still in memory. Close the child forms last.
"Go to, I’ll no more on’t; it hath made me mad." - Hamlet
|
|
|
|
|
Hi to all!!
I need a major project in visual basic...kindly help me out!!!
|
|
|
|
|
so you're looking for an idea for a major project, is that what you mean, how bout some specifics:
what did you already have in mind,?
what does it need to cover, topics etc?
what are you must comfortable with out of those topics?
|
|
|
|
|
Seriously, how is anyone supposed to answer this question?
There's is nothing here on what you know, the size of your team, if any, if there is any goal in doing to the project, what you intend to learn, industries your interested in, other projects you've done.
You've given us nothing to go on.
So, I can suggest a few. A control system for a nuclear power plant. Maybe a flight control system for an airliner. Engine and power management for the worlds largest container ships.
Those are all major projects...
|
|
|
|
|
Hello,
How can we recover deleted files in any format like .doc, .txt, .mdb from hard disk.
If anybody knows, please give URL or sample code.
Thanks & Regards,
Kumar
|
|
|
|
|
There's lots of stuff out there.
If you want to write your own, there is no URL I can give you. You must simplely know, and have experience with, file systems, especially NTFS and FAT, like you know the back of your hand.
|
|
|
|
|
Hi Dave Kreskowiak,
Thanks a lot for giving hint.
Thanks & Regards,
Kumar
|
|
|
|
|
Hi, I have written a simple program to better understand the concept of variable scope and I'd like your help in explaining a few things. My program simulates a ticketmaster, using a bunch of buttons to represent the number of available seats to a show. Every time a customer clicks on a button, its color turns from gray to blue. One seat will be subtracted from the total number of available seats when each button is clicked. I have created a global integer variable TotalSeats which represents the total number of seats available. The following code snippets are for the button which represents the first seat, and for the SHOW button to show the total number of available seats.
<br />
Dim TotalCount As Integer = 30<br />
<br />
Private Sub Seat1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Seat1.Click<br />
Dim A As Integer = 0<br />
While A < 1<br />
Seat1.BackColor = System.Drawing.Color.Blue<br />
A += 1<br />
TotalCount -= 1<br />
<br />
End While<br />
End Sub<br />
<br />
Private Sub SHOW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SHOW.Click<br />
<br />
Label1.Text = TotalCount<br />
End Sub
Please answer the following 2 questions, thank you in advance for your help.
1) I thought that TotalCount is a global variable and even though its being used in a private Sub, its should still be visible to the SHOW button, why does Label1 show that TotalCount is 30 and not 29?
2) How do I group all the seat buttons together so that I can use just one requiredvalidator for all of them?
|
|
|
|
|
It sounds like you are getting confused about the lifecycle of the pages in ASP.Net. Your scoping is correct. However your instance of this page class is created when the browser makes the request, then it renders the page, then the instance is disposed. This means that when your Click event handler is running, it is a totally new instance of the class, with a freshly initialized TotalCount.
You need to read up on the "asp.net page lifecycle" (google it), and look at how you can store information you need between requests in the ViewState.
|
|
|
|
|
Your code works well in Desktop Application
But You are using Web Appl so you have to clear about that
In Web App the client is on remote location when request arrives on server, it create new instance and send response to the client.
so when you click on button it generate new request to the server and it create new instance so you get refreshed value of Total Count.
Best Regards,
Chetan Patel
|
|
|
|
|
I'm using a WebBrowser Control to log into a website and download financial statements. I have IE6 installed and am using VB 2005 Express Edition. My problem is that I cannot suppress the dialog box which states "Security Alert - You are about to be redirected to a connection that is not secure".
I have tried hacking the registry without success (I understand WebBrowser Control uses standard IE6 SP1 settings) and cannot use SendKeys as I need this to run in the background. I can't see that CoInternetSetFeatureEnabled has the correct feature either. My last resort was to try IDocHostShowUI::ShowMessage but I can't find any sample code for VB to try out.
Having wasted around 12 hours of my life trying to find a solution i'm happy to make a financial donation to the first person to help me solve this issue!
Many thanks in advance,
Jonny
|
|
|
|
|
Hi Jonny,
If this is a task that should occur in the background, you might have a lot more luck with the System.Net.WebClient class.
Hope this helps,
|
|
|
|
|
Thanks for that Mark. Unfortunately i've already got quite a sizeable amount of code based around the WebBrowser control. If I can't find an alternative solution i'll certainly give the Net.WebClient class a go though.
Jonny
|
|
|
|
|
My VB .NET app is causing an unhandled exception. When I look at the exception details, it shows me the hex address where the exception is occurring. How I determine where in my code this is happening given an address?
Thanks
|
|
|
|
|
Look for code that calls a COM object, and set breakpoints to work out which one it is.
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
The exception is an "invalid typecast". I'm sure it is in my code. I don't believe it has anything to do with COM. Is there some sort of map file that that I can look at to find the method that contains the offending address.
I don't have the debugger on the target machine. An I'd rather not put it on the target. What if the exception happens out in the field? I'd like to be able to find the problem given the offending address.
|
|
|
|
|