Posting All of My Code to Get Help with an Error.

macupryk

Member
Joined
Apr 8, 2005
Messages
8
Programming Experience
10+
I have the following program:

Public Class TransOverride
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "


Private Sub TransOverride_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub TransOverride_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Disposed
MdiMain.FormList = Nothing
End Sub


Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
AddHandler DataGrid1.MouseUp, AddressOf highLightRow
Me.MdiParent = MdiMain.ParentWindow
Me.WindowState = FormWindowState.Maximized

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lblContents As System.Windows.Forms.Label
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents GroupBox17 As System.Windows.Forms.GroupBox
Friend WithEvents Label19 As System.Windows.Forms.Label
Friend WithEvents lbNumRec As System.Windows.Forms.Label
Friend WithEvents pdlgPrint As System.Windows.Forms.PrintDialog
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter
Friend WithEvents DsTransOverride1 As CCFinSol.DSTransOverride
' Declare primary columns for delete row
Dim PolicyNumber, TransCodeOrig, TransEffDate, ModifiedUID As String
Dim RowNum As Integer
Friend WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Friend WithEvents SqlDeleteCommand1 As System.Data.SqlClient.SqlCommand
Friend WithEvents SqlConnection2 As System.Data.SqlClient.SqlConnection
Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection



<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.lblContents = New System.Windows.Forms.Label
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.DsTransOverride1 = New CCFinSol.DSTransOverride
Me.GroupBox17 = New System.Windows.Forms.GroupBox
Me.lbNumRec = New System.Windows.Forms.Label
Me.Label19 = New System.Windows.Forms.Label
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlConnection2 = New System.Data.SqlClient.SqlConnection
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.GroupBox1.SuspendLayout()
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.DsTransOverride1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.GroupBox17.SuspendLayout()
Me.SuspendLayout()
'
'lblContents
'
Me.lblContents.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.lblContents.BackColor = System.Drawing.SystemColors.Desktop
Me.lblContents.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.lblContents.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblContents.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
Me.lblContents.Location = New System.Drawing.Point(0, 0)
Me.lblContents.Name = "lblContents"
Me.lblContents.Size = New System.Drawing.Size(998, 26)
Me.lblContents.TabIndex = 50
Me.lblContents.Text = "Transaction Override Application"
Me.lblContents.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.DataGrid1)
Me.GroupBox1.Controls.Add(Me.lblContents)
Me.GroupBox1.Location = New System.Drawing.Point(8, 16)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(1000, 488)
Me.GroupBox1.TabIndex = 52
Me.GroupBox1.TabStop = False
'
'DataGrid1
'
Me.DataGrid1.CaptionVisible = False
Me.DataGrid1.DataMember = ""
Me.DataGrid1.DataSource = Me.DsTransOverride1.dbo_stp_SelTransOverrides
Me.DataGrid1.HeaderFont = New System.Drawing.Font("Verdana", 15.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(8, 32)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(992, 456)
Me.DataGrid1.TabIndex = 51
'
'DsTransOverride1
'
Me.DsTransOverride1.DataSetName = "DSTransOverride1"
Me.DsTransOverride1.Locale = New System.Globalization.CultureInfo("en-US")
'
'GroupBox17
'
Me.GroupBox17.Controls.Add(Me.lbNumRec)
Me.GroupBox17.Controls.Add(Me.Label19)
Me.GroupBox17.Location = New System.Drawing.Point(824, 528)
Me.GroupBox17.Name = "GroupBox17"
Me.GroupBox17.Size = New System.Drawing.Size(176, 56)
Me.GroupBox17.TabIndex = 55
Me.GroupBox17.TabStop = False
'
'lbNumRec
'
Me.lbNumRec.BackColor = System.Drawing.SystemColors.Info
Me.lbNumRec.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.lbNumRec.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lbNumRec.Location = New System.Drawing.Point(24, 24)
Me.lbNumRec.Name = "lbNumRec"
Me.lbNumRec.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.lbNumRec.Size = New System.Drawing.Size(120, 22)
Me.lbNumRec.TabIndex = 50
Me.lbNumRec.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label19
'
Me.Label19.Font = New System.Drawing.Font("Verdana", 9.25!, System.Drawing.FontStyle.Bold)
Me.Label19.ImeMode = System.Windows.Forms.ImeMode.NoControl
Me.Label19.Location = New System.Drawing.Point(8, 0)
Me.Label19.Name = "Label19"
Me.Label19.Size = New System.Drawing.Size(160, 16)
Me.Label19.TabIndex = 0
Me.Label19.Text = " Number of Records:"
'
'SqlDataAdapter1
'
Me.SqlDataAdapter1.DeleteCommand = Me.SqlDeleteCommand1
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "dbo_stp_SelTransOverrides", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Account Name", "Account Name"), New System.Data.Common.DataColumnMapping("Policy Number", "Policy Number"), New System.Data.Common.DataColumnMapping("Original Transaction Code", "Original Transaction Code"), New System.Data.Common.DataColumnMapping("Trans. Eff. Date", "Trans. Eff. Date"), New System.Data.Common.DataColumnMapping("Override Action", "Override Action"), New System.Data.Common.DataColumnMapping("Override New/Renewal", "Override New/Renewal"), New System.Data.Common.DataColumnMapping("Override Transaction Code", "Override Transaction Code"), New System.Data.Common.DataColumnMapping("UserId", "UserId"), New System.Data.Common.DataColumnMapping("Date", "Date"), New System.Data.Common.DataColumnMapping("Plan Year", "Plan Year")})})
'
'SqlDeleteCommand1
'
Me.SqlDeleteCommand1.CommandText = "dbo.[stp_DelTransOverride]"
Me.SqlDeleteCommand1.CommandType = System.Data.CommandType.StoredProcedure
Me.SqlDeleteCommand1.Connection = Me.SqlConnection2
Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Policy_Nbr", System.Data.SqlDbType.VarChar, 7, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Original, Nothing))
Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Trans_CodeOrig", System.Data.SqlDbType.VarChar, 6, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Original, Nothing))
Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Trans_Eff_Date", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Original, Nothing))
Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ModifiedUID", System.Data.SqlDbType.NVarChar, 48, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Original, Nothing))
'
'SqlConnection2
'
Me.SqlConnection2.ConnectionString = "workstation id=""SERVER-OMEGA"";packet size=4096;user id=CCFinSol;data source=USZZD" & _
"SCHVWB11;persist security info=True;initial catalog=CCFinSol;password=CCFinSol"
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "dbo.[stp_SelTransOverrides]"
Me.SqlSelectCommand1.CommandType = System.Data.CommandType.StoredProcedure
Me.SqlSelectCommand1.Connection = Me.SqlConnection2
Me.SqlSelectCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "workstation id=""SERVER-OMEGA"";packet size=4096;user id=CCFinSol;data source=USZZD" & _
"SCHVWB11;persist security info=True;initial catalog=CCFinSol;password=CCFinSol"
'
'TransOverride
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(1028, 614)
Me.Controls.Add(Me.GroupBox17)
Me.Controls.Add(Me.GroupBox1)
Me.Name = "TransOverride"
Me.Text = "Tansaction Override"
Me.GroupBox1.ResumeLayout(False)
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.DsTransOverride1, System.ComponentModel.ISupportInitialize).EndInit()
Me.GroupBox17.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region
#Region "MDI Main functions interface"

Public Sub DoPrint()
' Me.PrintPreviewUtilityTab(Me.Trans_Override)
End Sub
Public Sub doDelete()
Dim bm As BindingManagerBase = Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember)
Dim dr As DataRow = CType(bm.Current, DataRowView).Row
dr.delete()
' then update you dataadapter

SqlDataAdapter1.update(Me.DsTransOverride1, "dbo_stp_SelTransOverrides")
DsTransOverride1.dbo_stp_SelTransOverrides.acceptchanges()
End Sub
#End Region

Private Sub PrintPreviewUtilityTab(ByVal tgrd As C1.Win.C1TrueDBGrid.C1TrueDBGrid)
Try
Me.pdlgPrint.PrinterSettings = New System.Drawing.Printing.PrinterSettings
If Me.pdlgPrint.ShowDialog(Me) = DialogResult.Cancel Then
Exit Sub
End If

Catch exc As Exception
MessageBox.Show(Text:="Utility table listing printer selection error." & _
Microsoft.VisualBasic.ControlChars.Cr & _
exc.Message, _
Buttons:=MessageBoxButtons.OK, Icon:=MessageBoxIcon.Error, _
Caption:=Me.GetType.ToString())

Exit Sub
End Try

Dim fntHdrFtr As System.Drawing.Font
fntHdrFtr = New System.Drawing.Font(Me.Font.Name, 14, FontStyle.Bold)
Dim PI As C1.Win.C1TrueDBGrid.PrintInfo
PI = tgrd.PrintInfo
With PI
PI.PageSettings.PrinterSettings.PrinterName = Me.pdlgPrint.PrinterSettings.PrinterName
.VarRowHeight = C1.Win.C1TrueDBGrid.PrintInfo.RowHeightEnum.LikeGrid
.PageBreak = C1.Win.C1TrueDBGrid.PrintInfo.PageBreaksEnum.FitIntoArea

Dim sRptTableName As String
sRptTableName = "Transaction Processing Override"
.PageSettings.Landscape = False
.PageHeaderStyle.Font = fntHdrFtr
.PageHeader = Microsoft.VisualBasic.ControlChars.Tab & sRptTableName _
& Microsoft.VisualBasic.ControlChars.Tab & "Page: \p"
.ShowOptionsDialog = False

.PageFooterStyle.Font = fntHdrFtr
.PageFooter = clsRunParms.FullName() & " " & New String(Microsoft.VisualBasic.ControlChars.Tab, 2) _
& String.Format("{0:MM/dd/yyyy}", DateTime.Now())
.ShowSelection = False

.PageSettings.Margins.Top = 90
.PageSettings.Margins.Bottom = 65
.PageSettings.Margins.Left = 50
.PageSettings.Margins.Right = 50

End With

Dim PPWS As C1.Win.C1TrueDBGrid.PrintPreviewWinSettings
PPWS = tgrd.PreviewInfo

With PPWS

.Location = Me.PointToScreen(New Point(0, 0))
.Size = Me.ClientSize
.AllowSizing = False
.NavigationPaneDockingStyle = DockStyle.None
.ToolBars = True

End With
Try
PI.Print(Me.pdlgPrint.PrinterSettings)

Catch exc As Exception
MessageBox.Show(Text:="Utility table listing printing error." & _
Microsoft.VisualBasic.ControlChars.Cr & _
exc.Message, _
Buttons:=MessageBoxButtons.OK, Icon:=MessageBoxIcon.Error, _
Caption:=Me.GetType.ToString())

End Try

End Sub

#Region " DataGrid MouseUp Event "
Private Sub highLightRow(ByVal sender As Object, ByVal e As MouseEventArgs)

Dim pt = New Point(e.X, e.Y)
Dim grd As DataGrid = CType(sender, DataGrid)
Dim hit As DataGrid.HitTestInfo = grd.HitTest(pt)

If hit.Type = grd.HitTestType.Cell Then
grd.CurrentCell = New DataGridCell(hit.Row, hit.Column)
RowNum = hit.Row
grd.Select(RowNum)
End If
End Sub
#End Region

Private Sub TransOverride_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DataGridTextBoxColumn1 As New DataGridTextBoxColumn
Dim DataGridTextBoxColumn2 As New DataGridTextBoxColumn
Dim DataGridTextBoxColumn3 As New DataGridTextBoxColumn
Dim DataGridTextBoxColumn4 As New DataGridTextBoxColumn
Dim DataGridTextBoxColumn5 As New DataGridTextBoxColumn
Dim DataGridTextBoxColumn6 As New DataGridTextBoxColumn
Dim DataGridTextBoxColumn7 As New DataGridTextBoxColumn
Dim DataGridTextBoxColumn8 As New DataGridTextBoxColumn
Dim DataGridTextBoxColumn9 As New DataGridTextBoxColumn
Dim DataGridTextBoxColumn10 As New DataGridTextBoxColumn
Dim DataGridTableStyle1 As New DataGridTableStyle

Me.SqlDataAdapter1.Fill(Me.DsTransOverride1)
'Step 1: Create a DataGridTableStyle &
' set mappingname to table.

'
'DataGridTableStyle1
'
DataGrid1.TableStyles.Clear()
DataGridTableStyle1.DataGrid = Me.DataGrid1
DataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText
DataGridTableStyle1.MappingName = "dbo_stp_SelTransOverrides"



'Step 2: Create DataGridColumnStyle for each col
'
'DataGridTextBoxColumn1
'
DataGridTextBoxColumn1.HeaderText = "Account Name"
DataGridTextBoxColumn1.MappingName = "Account Name"
DataGridTextBoxColumn1.Width = 244
DataGridTextBoxColumn1.ReadOnly = True
DataGridTextBoxColumn1.Alignment = HorizontalAlignment.Left
DataGridTextBoxColumn1.TextBox.Enabled = True
DataGridTextBoxColumn1.TextBox.Multiline = True
DataGridTextBoxColumn1.TextBox.WordWrap = True
DataGridTextBoxColumn1.TextBox.CharacterCasing = CharacterCasing.Upper
DataGridTextBoxColumn1.Format = ""
DataGridTextBoxColumn1.FormatInfo = Nothing
DataGridTableStyle1.GridColumnStyles.Add(DataGridTextBoxColumn1)

'
'DataGridTextBoxColumn2
'
DataGridTextBoxColumn2.HeaderText = "Policy Number"
DataGridTextBoxColumn2.MappingName = "Policy Number"
DataGridTextBoxColumn2.Width = 78
DataGridTextBoxColumn2.ReadOnly = True
DataGridTextBoxColumn2.Alignment = HorizontalAlignment.Left
DataGridTextBoxColumn2.TextBox.Enabled = True
DataGridTextBoxColumn2.TextBox.Multiline = True
DataGridTextBoxColumn2.TextBox.WordWrap = True
DataGridTextBoxColumn2.TextBox.CharacterCasing = CharacterCasing.Upper
DataGridTextBoxColumn2.Format = ""
DataGridTextBoxColumn2.FormatInfo = Nothing
DataGridTableStyle1.GridColumnStyles.Add(DataGridTextBoxColumn2)
'
'DataGridTextBoxColumn3
'
DataGridTextBoxColumn3.HeaderText = "Original Trans." & vbCrLf & "Code"
DataGridTextBoxColumn3.MappingName = "Original Transaction Code"
DataGridTextBoxColumn3.Width = 80
DataGridTextBoxColumn3.ReadOnly = True
DataGridTextBoxColumn3.Alignment = HorizontalAlignment.Left
DataGridTextBoxColumn3.TextBox.Enabled = True
DataGridTextBoxColumn3.TextBox.Multiline = True
DataGridTextBoxColumn3.TextBox.WordWrap = True
DataGridTextBoxColumn3.TextBox.CharacterCasing = CharacterCasing.Upper
DataGridTextBoxColumn3.Format = ""
DataGridTextBoxColumn3.FormatInfo = Nothing
DataGridTableStyle1.GridColumnStyles.Add(DataGridTextBoxColumn3)
'
'DataGridTextBoxColumn4
'
DataGridTextBoxColumn4.HeaderText = "Trans. Eff. Date"
DataGridTextBoxColumn4.MappingName = "Trans. Eff. Date"
DataGridTextBoxColumn4.Width = 85
DataGridTextBoxColumn4.ReadOnly = True
DataGridTextBoxColumn4.Alignment = HorizontalAlignment.Left
DataGridTextBoxColumn4.TextBox.Enabled = True
DataGridTextBoxColumn4.TextBox.Multiline = True
DataGridTextBoxColumn4.TextBox.WordWrap = True
DataGridTextBoxColumn4.TextBox.CharacterCasing = CharacterCasing.Upper
DataGridTextBoxColumn4.Format = ""
DataGridTextBoxColumn4.FormatInfo = Nothing

DataGridTableStyle1.GridColumnStyles.Add(DataGridTextBoxColumn4)
'
'DataGridTextBoxColumn5
'
DataGridTextBoxColumn5.HeaderText = "Override Action"
DataGridTextBoxColumn5.MappingName = "Override Action"
DataGridTextBoxColumn5.Width = 83
DataGridTextBoxColumn5.ReadOnly = True
DataGridTextBoxColumn5.Alignment = HorizontalAlignment.Left
DataGridTextBoxColumn5.TextBox.Enabled = True
DataGridTextBoxColumn5.TextBox.Multiline = True
DataGridTextBoxColumn5.TextBox.WordWrap = True
DataGridTextBoxColumn5.TextBox.CharacterCasing = CharacterCasing.Upper
DataGridTextBoxColumn5.Format = ""
DataGridTextBoxColumn5.FormatInfo = Nothing
DataGridTableStyle1.GridColumnStyles.Add(DataGridTextBoxColumn5)

'
'DataGridTextBoxColumn6
'
DataGridTextBoxColumn6.HeaderText = "Override N/R"
DataGridTextBoxColumn6.MappingName = "Override New/Renewal"
DataGridTextBoxColumn6.Width = 72
DataGridTextBoxColumn6.ReadOnly = True
DataGridTextBoxColumn6.Alignment = HorizontalAlignment.Left
DataGridTextBoxColumn6.TextBox.Enabled = True
DataGridTextBoxColumn6.TextBox.Multiline = True
DataGridTextBoxColumn6.TextBox.WordWrap = True
DataGridTextBoxColumn6.TextBox.CharacterCasing = CharacterCasing.Upper
DataGridTextBoxColumn6.Format = ""
DataGridTextBoxColumn6.FormatInfo = Nothing
DataGridTableStyle1.GridColumnStyles.Add(DataGridTextBoxColumn6)

'
'DataGridTextBoxColumn7
'
DataGridTextBoxColumn7.HeaderText = "Override Trans." & vbCrLf & "Code"
DataGridTextBoxColumn7.MappingName = "Override Transaction Code"
DataGridTextBoxColumn7.Width = 84
DataGridTextBoxColumn7.ReadOnly = True
DataGridTextBoxColumn7.Alignment = HorizontalAlignment.Left
DataGridTextBoxColumn7.TextBox.Enabled = True
DataGridTextBoxColumn7.TextBox.Multiline = True
DataGridTextBoxColumn7.TextBox.WordWrap = True
DataGridTextBoxColumn7.TextBox.CharacterCasing = CharacterCasing.Upper
DataGridTextBoxColumn7.Format = ""
DataGridTextBoxColumn7.FormatInfo = Nothing
DataGridTableStyle1.GridColumnStyles.Add(DataGridTextBoxColumn7)

'
'DataGridTextBoxColumn8
'
DataGridTextBoxColumn8.HeaderText = "UserId"
DataGridTextBoxColumn8.MappingName = "UserId"
DataGridTextBoxColumn8.Width = 80
DataGridTextBoxColumn8.ReadOnly = True
DataGridTextBoxColumn8.Alignment = HorizontalAlignment.Left
DataGridTextBoxColumn8.TextBox.Enabled = True
DataGridTextBoxColumn8.TextBox.Multiline = True
DataGridTextBoxColumn8.TextBox.WordWrap = True
DataGridTextBoxColumn8.TextBox.CharacterCasing = CharacterCasing.Upper
DataGridTextBoxColumn8.Format = ""
DataGridTextBoxColumn8.FormatInfo = Nothing
DataGridTableStyle1.GridColumnStyles.Add(DataGridTextBoxColumn8)

'
'DataGridTextBoxColumn9
'
DataGridTextBoxColumn9.HeaderText = "Modified Date"
DataGridTextBoxColumn9.MappingName = "Date"
DataGridTextBoxColumn9.Width = 76
DataGridTextBoxColumn9.ReadOnly = True
DataGridTextBoxColumn9.Alignment = HorizontalAlignment.Left
DataGridTextBoxColumn9.TextBox.Enabled = True
DataGridTextBoxColumn9.TextBox.Multiline = True
DataGridTextBoxColumn9.TextBox.WordWrap = True
DataGridTextBoxColumn9.TextBox.CharacterCasing = CharacterCasing.Upper
DataGridTextBoxColumn9.Format = "MM/dd/yyyy"
DataGridTextBoxColumn9.FormatInfo = Nothing
DataGridTableStyle1.GridColumnStyles.Add(DataGridTextBoxColumn9)

'
'DataGridTextBoxColumn10
'
DataGridTextBoxColumn10.HeaderText = "Plan Year"
DataGridTextBoxColumn10.MappingName = "Plan Year"
DataGridTextBoxColumn10.Width = 55
DataGridTextBoxColumn10.ReadOnly = True
DataGridTextBoxColumn10.Alignment = HorizontalAlignment.Left
DataGridTextBoxColumn10.TextBox.Enabled = True
DataGridTextBoxColumn10.TextBox.Multiline = True
DataGridTextBoxColumn10.TextBox.WordWrap = True
DataGridTextBoxColumn10.TextBox.CharacterCasing = CharacterCasing.Upper
DataGridTextBoxColumn10.Format = ""
DataGridTextBoxColumn10.FormatInfo = Nothing
DataGridTableStyle1.GridColumnStyles.Add(DataGridTextBoxColumn10)

'Step 3: Add the tablestyle to the datagrid
' Make the dataGrid use our new tablestyle and bind it to our table
DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(DataGridTableStyle1)

Me.lbNumRec.Text = Me.DsTransOverride1.Tables(0).Rows.Count.ToString()
End Sub
Private Sub SqlDataAdapter1_RowUpdated(ByVal sender As System.Object, ByVal e As System.Data.SqlClient.SqlRowUpdatedEventArgs)


End Sub



Private Sub Trans_Override_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

' Dim dTable As DataTable = Me.Trans_Override.DataSource
' Dim dRow As DataRow = dTable.Rows(Me.Trans_Override.Row)
'Me.lbNumRec.Text = Me.DsTransOverride1.Tables(0).Rows.Count.ToString()
' Dim f As New EditTransOverride
' f.row = dRow
' f.rowNo = Me.Trans_Override.Row + 1
' f.ShowDialog()
' Me.SqlDataAdapter1.Update(Me.DsTransOverride1)
' Me.DsTransOverride1.Tables(0).Clear()
'Me.SqlDataAdapter1.Fill(Me.DsTransOverride1)
' Me.Trans_Override.Refresh()


End Sub

Private Sub lbNumRec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbNumRec.Click

End Sub


Private Sub Trans_Override_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate

End Sub

Private Sub SqlConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.SqlClient.SqlInfoMessageEventArgs) Handles SqlConnection1.InfoMessage

End Sub

Private Sub SqlDataAdapter1_RowUpdated_1(ByVal sender As System.Object, ByVal e As System.Data.SqlClient.SqlRowUpdatedEventArgs) Handles SqlDataAdapter1.RowUpdated

End Sub
End Class


If fails on

Public Sub doDelete()
Dim bm As BindingManagerBase = Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember)
Dim dr As DataRow = CType(bm.Current, DataRowView).Row
dr.delete()
' then update you dataadapter

===>>>>>>> SqlDataAdapter1.update(Me.DsTransOverride1, "dbo_stp_SelTransOverrides")
DsTransOverride1.dbo_stp_SelTransOverrides.acceptchanges()
End Sub



How can I catch or find out what this error is:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

Additional information: System error.

Sorry I had to post all the code. But to understand the error I had too.

Thank You for any help you can give me doesnt matter how small. That is the funny thing it probally is something small...


Thanks again,
M
 
Replace your problem line with the following code snip:

VB.NET:
Try
    SqlDataAdapter1.update(Me.DsTransOverride1, "dbo_stp_SelTransOverrides")
Catch sqlex AsSystem.Data.SqlClient.SqlException
  MessageBox.Show sqlex.ToString
End Try

What's happening is that the SQL is returning an error. The above code will trap the SQL error specificaly and display it.

-tg
 
I get the following error.

Public Sub doDelete()
Dim bm As BindingManagerBase = Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember)
Dim dr As DataRow = CType(bm.Current, DataRowView).Row
Try
dr.Delete()
SqlDataAdapter1.Update(Me.DsTransOverride1, "dbo_stp_SelTransOverrides")
DsTransOverride1.dbo_stp_SelTransOverrides.AcceptChanges()
Catch exError As Exception
MessageBox.Show(exError.Message)
End Try
End Sub

and I get the message

Procedure 'stp_DelTransOverride' expects parameter '@Policy_Nbr', which was not supplied.
 
Please read also this.

I modifed
Public Sub doDelete()
Dim bm As BindingManagerBase = Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember)
Dim dr As DataRow = CType(bm.Current, DataRowView).Row
Try
dr.Delete()
SqlDataAdapter1.Update(Me.DsTransOverride1, "dbo_stp_SelTransOverrides")
DsTransOverride1.dbo_stp_SelTransOverrides.AcceptChanges()
Catch exError As Exception
MessageBox.Show(exError.Message)
End Try
End Sub

and I get the message

Procedure 'stp_DelTransOverride' expects parameter '@Policy_Nbr', which was not supplied.

And someone is saying:

you have this line:

Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Policy_Nbr", System.Data.SqlDbType.VarChar, 7, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Original, Nothing))

It needs to know the column name in the table that has the value for this. If it is Policy_Nbr then the line should read

Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Policy_Nbr", System.Data.SqlDbType.VarChar, 7, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Original, "Policy_Nbr"))

the other lines will need to have similar changes.

My stored procedure is as follows:

My delete procedure is as follows?

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO


CREATE PROCEDURE dbo.stp_DelTransOverride

@Policy_Nbr varchar(7),
@Trans_CodeOrig varchar(6),
@Trans_Eff_Date datetime,
@ModifiedUID nvarchar(48) -- may be used for loggin in the future
AS
BEGIN
SET NOCOUNT ON

-- Delete the TransOverride
DELETE FROM dbo.TransOverride
WHERE Policy_Nbr = @Policy_Nbr AND Trans_CodeOrig = @Trans_CodeOrig AND Trans_Eff_Date = @Trans_Eff_Date

RETURN 0

END


GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
 
Add

Dim NumberPolicy As New SqlClient.SqlParameter("@Numbr_Policy", SqlDbType.NVarChar)

NumberPolicy.Value = whatever the source is

add this parameter before running the update.
 

Latest posts

Back
Top