Click here to Skip to main content
15,911,524 members

Comments by Member 8576839 (Top 1 by date)

Member 8576839 4-Feb-12 5:57am View    
Private Sub btnsav_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsav.Click

If txtcode.Text = "" Then
MessageBox.Show("Enter the Material Code", "Code", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtcode.Focus()
Exit Sub
End If
If txtname.Text = "" Then
MessageBox.Show("Enter the Material Name", "Name", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtname.Focus()
Exit Sub
End If

If txtunit.Text = "" Then
MessageBox.Show("Enter the Unit", "Unit", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtunit.Focus()

Exit Sub
End If
Try

If Mode = "New" Then

If MessageBox.Show("Are you sure to store the values​​.!!!", "New Material", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.No Then Exit Sub

flag = cn.executeQuery(" insert into tbl_Mat_Master values ('" & txtcode.Text & "','" & txtname.Text & "','" & txtunit.Text & "') ")

If flag = True Then
MessageBox.Show("Record Inserted Successfully", "Raw Material", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Unable to Save Record", "Raw Material", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
ElseIf Mode = "Edit" Then
If MessageBox.Show("Are You want to Edit the record", "Edit", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.No Then Exit Sub


flag = cn.executeQuery(" UPDATE tbl_mat_master SET Mat_Name= '" & txtname.Text & "', Unit = '" & txtunit.Text & "' WHERE Mat_Code= '" & txtcode.Text & "' ")

If flag = True Then
MessageBox.Show("Record Updated Successfully", "Raw Material", MessageBoxButtons.OK, MessageBoxIcon.Information)

End If
End If


Catch ex As Exception
cn.DisplayErrorDialog(ex)
cn.WriteToErrorLog(ex.Message, ex.StackTrace, "Error")

End Try
End Sub


it is my save button coding i use MSSql 2008 and Microsoft visual studio 2010