Click here to Skip to main content
15,507,755 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am using viewstate to store the row of values from grid but this is very problematic while insertin the values into the database . Please suggest another solution for the same.
Updated 10-Feb-14 0:14am
What is the exact problem with ViewState?
Ni!E$H_WAGH 10-Feb-14 7:44am    
Viewstate not storing the last row of values from the gridview .
Show your code. It should store. You must be doing something wrong.
Ni!E$H_WAGH 10-Feb-14 7:50am    
This is the code for Save button
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
'Please do not double click this button to view code.
'If you double click it will generate Handles event due to which the
'values will be inserted twice into the database

Dim table As DataTable = TryCast(ViewState("CurrentTable"), DataTable)

If table IsNot Nothing Then
For Each row As DataRow In table.Rows
Dim funob As String = TryCast(row.ItemArray(1), String)
Dim measur As String = TryCast(row.ItemArray(2), String)
Dim d_line As String = TryCast(row.ItemArray(3), String)
Dim wtfact As String = TryCast(row.ItemArray(4), String)

'If funob IsNot Nothing OrElse measur IsNot Nothing OrElse d_line IsNot Nothing OrElse wtfact IsNot Nothing Then
If funob IsNot Nothing Or measur IsNot Nothing Or d_line IsNot Nothing Or wtfact IsNot Nothing Then

Dim cmd As New SqlCommand
Dim obj As New GenericCode
Dim str As String
Dim con As New SqlConnection
Dim empcode As String = Session("emp_code")
con.ConnectionString = strConnString
str = " insert into MBO_Details(MBO_EMP_Code,MBO_FUNC_OBJ,MBO_MEASURED_VAR,MBO_DEADLINE,MBO_WEIGHT_FACT) values ('" & empcode & "','"
str = str & funob & "','" & measur & "','" & d_line & "','" & wtfact & "')"

cmd.CommandText = str
cmd = New SqlCommand(str, con)

End If
lblusrmsg.Visible = True
btnSave.Enabled = False
ButtonAdd.Enabled = False

End If
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900