I am getting the error:
System.Data.OleDb.OleDbException: No value given for one or more required parameters.
Here is my code.
<asp:GridView
ID="GridView1"
runat="server"
Font-Size="X-Small"
AutoGenerateColumns="False"
OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:CommandField ShowEditButton="True" UpdateText="UPDATE"/>
<asp:BoundField DataField="Accepted" HeaderText="Accepted" SortExpression="Accepted" />
<asp:BoundField DataField="Unit" HeaderText="Unit" SortExpression="Unit" />
<asp:BoundField DataField="OutageType" HeaderText="OutageType" SortExpression="OutageType" />
<asp:BoundField DataField="StartTime" HeaderText="StartTime" SortExpression="StartTime" />
<asp:BoundField DataField="EndTime" HeaderText="EndTime" SortExpression="EndTime" />
<asp:BoundField DataField="Capacity" HeaderText="Capacity" SortExpression="Capacity" />
<asp:BoundField DataField="NetCapacity" HeaderText="NetCapacity" SortExpression="NetCapacity" />
<asp:BoundField DataField="DurationHours" HeaderText="DurationHours" SortExpression="DurationHours" HtmlEncode="false" dataformatstring="{0:n}"/>
<asp:BoundField DataField="MWhLost1" HeaderText="MWhLost1" SortExpression="MWhLost1" />
<asp:BoundField DataField="CauseCode1" HeaderText="CauseCode1" SortExpression="CauseCode1" />
<asp:BoundField DataField="Cause1Desc" HeaderText="Cause1Desc" SortExpression="Cause1Desc" />
<asp:BoundField DataField="CauseCode2" HeaderText="CauseCode2" SortExpression="CauseCode2" />
<asp:BoundField DataField="Cause2Desc" HeaderText="Cause2Desc" SortExpression="Cause2Desc" />
<asp:BoundField DataField="MWhLost2" HeaderText="MWhLost2" SortExpression="MWhLost2" />
<asp:BoundField DataField="User1" HeaderText="User1" SortExpression="User1" />
<asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments" />
</Columns>
</asp:GridView>
Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Dim cmd As New OleDb.OleDbCommand
Dim sql As String
Dim txtAccepted As String = e.RowIndex.ToString
Dim txtUnit As String = e.RowIndex.ToString
Dim txtOutageType As String = e.RowIndex.ToString
Dim txtStartTime As String = e.RowIndex.ToString
Dim txtEndTime As String = e.RowIndex.ToString
Dim txtCapacity As String = e.RowIndex.ToString
Dim txtNetCapacity As String = e.RowIndex.ToString
Dim txtDurationHours As String = e.RowIndex.ToString
Dim txtMWhLost1 As String = e.RowIndex.ToString
Dim txtCauseCode1 As String = e.RowIndex.ToString
Dim txtCause1Desc As String = e.RowIndex.ToString
Dim txtCauseCode2 As String = e.RowIndex.ToString
Dim txtCause2Desc As String = e.RowIndex.ToString
Dim txtMWhLost2 As String = e.RowIndex.ToString
Dim txtUser1 As String = e.RowIndex.ToString
Dim txtComments As String = e.RowIndex.ToString
cmd.Parameters.Add(New OleDb.OleDbParameter("@Accepted", txtAccepted.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@Unit", txtUnit.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@OutageType", txtOutageType.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@StartTime", txtStartTime.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@EndTime", txtEndTime.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@Capacity", txtCapacity.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@NetCapacity", txtNetCapacity.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@DurationHours", txtDurationHours.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@MWhLost1", txtMWhLost1.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@CauseCode1", txtCauseCode1.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@Cause1Desc", txtCause1Desc.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@CauseCode2", txtCauseCode2.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@Cause2Desc", txtCause2Desc.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@MWhLost2", txtMWhLost2.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@User1", txtUser1.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@Comments", txtComments.ToString))
sql = "UPDATE Events SET [Accepted]=@Accepted,[Unit]=@Unit,[StartTime]=@StartTime,[EndTime]=@EndTime,[OutageType]=@OutageType,[Capacity]=@Capacity,[NetCapacity]=@NetCapacity,[DurationHours]=@DurationHours,[MWhLost1]=@MWhLost1,[CauseCode1]=@CauseCode1,[Cause1Desc]=@Cause1Desc,[CauseCode2]=@CauseCode2,[Cause2Desc]=@Cause2Desc,[MWhLost2]=@MWhLost2,[User1]=@User1,[Comments]=@Comments WHERE [Unit]=@Unit AND [StartTime]=@StartTime AND [EndTime]=@EndTime"
Con.ConnectionString = connString
Con.Open()
cmd = New OleDb.OleDbCommand(sql, Con)
cmd.ExecuteNonQuery()
Con.Close()
GridView1.EditIndex = -1
BindData()
End Sub
Searches online say that this error comes up when something is misspelled or called and does not exist. But I have looked and that is not the problem.
Any help is worth a star!!!
Thanks chilly442
System.Data.OleDb.OleDbException: No value given for one or more required parameters.
Here is my code.
<asp:GridView
ID="GridView1"
runat="server"
Font-Size="X-Small"
AutoGenerateColumns="False"
OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:CommandField ShowEditButton="True" UpdateText="UPDATE"/>
<asp:BoundField DataField="Accepted" HeaderText="Accepted" SortExpression="Accepted" />
<asp:BoundField DataField="Unit" HeaderText="Unit" SortExpression="Unit" />
<asp:BoundField DataField="OutageType" HeaderText="OutageType" SortExpression="OutageType" />
<asp:BoundField DataField="StartTime" HeaderText="StartTime" SortExpression="StartTime" />
<asp:BoundField DataField="EndTime" HeaderText="EndTime" SortExpression="EndTime" />
<asp:BoundField DataField="Capacity" HeaderText="Capacity" SortExpression="Capacity" />
<asp:BoundField DataField="NetCapacity" HeaderText="NetCapacity" SortExpression="NetCapacity" />
<asp:BoundField DataField="DurationHours" HeaderText="DurationHours" SortExpression="DurationHours" HtmlEncode="false" dataformatstring="{0:n}"/>
<asp:BoundField DataField="MWhLost1" HeaderText="MWhLost1" SortExpression="MWhLost1" />
<asp:BoundField DataField="CauseCode1" HeaderText="CauseCode1" SortExpression="CauseCode1" />
<asp:BoundField DataField="Cause1Desc" HeaderText="Cause1Desc" SortExpression="Cause1Desc" />
<asp:BoundField DataField="CauseCode2" HeaderText="CauseCode2" SortExpression="CauseCode2" />
<asp:BoundField DataField="Cause2Desc" HeaderText="Cause2Desc" SortExpression="Cause2Desc" />
<asp:BoundField DataField="MWhLost2" HeaderText="MWhLost2" SortExpression="MWhLost2" />
<asp:BoundField DataField="User1" HeaderText="User1" SortExpression="User1" />
<asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments" />
</Columns>
</asp:GridView>
Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Dim cmd As New OleDb.OleDbCommand
Dim sql As String
Dim txtAccepted As String = e.RowIndex.ToString
Dim txtUnit As String = e.RowIndex.ToString
Dim txtOutageType As String = e.RowIndex.ToString
Dim txtStartTime As String = e.RowIndex.ToString
Dim txtEndTime As String = e.RowIndex.ToString
Dim txtCapacity As String = e.RowIndex.ToString
Dim txtNetCapacity As String = e.RowIndex.ToString
Dim txtDurationHours As String = e.RowIndex.ToString
Dim txtMWhLost1 As String = e.RowIndex.ToString
Dim txtCauseCode1 As String = e.RowIndex.ToString
Dim txtCause1Desc As String = e.RowIndex.ToString
Dim txtCauseCode2 As String = e.RowIndex.ToString
Dim txtCause2Desc As String = e.RowIndex.ToString
Dim txtMWhLost2 As String = e.RowIndex.ToString
Dim txtUser1 As String = e.RowIndex.ToString
Dim txtComments As String = e.RowIndex.ToString
cmd.Parameters.Add(New OleDb.OleDbParameter("@Accepted", txtAccepted.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@Unit", txtUnit.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@OutageType", txtOutageType.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@StartTime", txtStartTime.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@EndTime", txtEndTime.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@Capacity", txtCapacity.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@NetCapacity", txtNetCapacity.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@DurationHours", txtDurationHours.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@MWhLost1", txtMWhLost1.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@CauseCode1", txtCauseCode1.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@Cause1Desc", txtCause1Desc.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@CauseCode2", txtCauseCode2.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@Cause2Desc", txtCause2Desc.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@MWhLost2", txtMWhLost2.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@User1", txtUser1.ToString))
cmd.Parameters.Add(New OleDb.OleDbParameter("@Comments", txtComments.ToString))
sql = "UPDATE Events SET [Accepted]=@Accepted,[Unit]=@Unit,[StartTime]=@StartTime,[EndTime]=@EndTime,[OutageType]=@OutageType,[Capacity]=@Capacity,[NetCapacity]=@NetCapacity,[DurationHours]=@DurationHours,[MWhLost1]=@MWhLost1,[CauseCode1]=@CauseCode1,[Cause1Desc]=@Cause1Desc,[CauseCode2]=@CauseCode2,[Cause2Desc]=@Cause2Desc,[MWhLost2]=@MWhLost2,[User1]=@User1,[Comments]=@Comments WHERE [Unit]=@Unit AND [StartTime]=@StartTime AND [EndTime]=@EndTime"
Con.ConnectionString = connString
Con.Open()
cmd = New OleDb.OleDbCommand(sql, Con)
cmd.ExecuteNonQuery()
Con.Close()
GridView1.EditIndex = -1
BindData()
End Sub
Searches online say that this error comes up when something is misspelled or called and does not exist. But I have looked and that is not the problem.
Any help is worth a star!!!
Thanks chilly442