I am trying to update my datagrid as well as database using the following code in vb.net, but i am not able to succeed it.I do not get any errors at the same time nor does the grid/databse get updated.Can anyone please help me.It is very urgent!!!!!
This is my Update Code,
and FillDatagrid is the following,
Can someone tell where am i doing wrong. It is very urgent and i need the solution before noon today. I appreaciate your help.
Thanks,
Simran
This is my Update Code,
VB.NET:
Public Sub DataGrid1_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dim newtitle, newname, newdate, newtarget, newbase, newmulti, newpool, newprop, newf1, newf2, newf3 As String
Dim empid As Integer
empid = Integer.Parse(CType(e.Item.Cells(1).Controls(0), TextBox).Text)
newname = CType(e.Item.Cells(2).Controls(0), TextBox).Text
newtitle = CType(e.Item.Cells(3).Controls(0), TextBox).Text
newdate = CType(e.Item.Cells(4).Controls(0), TextBox).Text
newtarget = CType(e.Item.Cells(5).Controls(0), TextBox).Text
newbase = CType(e.Item.Cells(6).Controls(0), TextBox).Text
newmulti = CType(e.Item.Cells(7).Controls(0), TextBox).Text
newpool = CType(e.Item.Cells(8).Controls(0), TextBox).Text
newprop = CType(e.Item.Cells(9).Controls(0), TextBox).Text
newf1 = CType(e.Item.Cells(10).Controls(0), TextBox).Text
newf2 = CType(e.Item.Cells(11).Controls(0), TextBox).Text
newf3 = CType(e.Item.Cells(12).Controls(0), TextBox).Text
empid = DataGrid1.DataKeys(e.Item.ItemIndex)
Dim ins As String = "update MAIN set NAME= @nname,TITLE=@ntitle,ENTRY_DATE=@ndate, TA
RGET=@ntarget,
[EMAIL="BASE_SAL=@nbase,MULTIPLIER=@nmulti,INC_POOL=@npool,PROPOSED_INC=@nprop,FI"]BASE_SAL=@nbase,MULTIPLIER=@nmulti,INC_POOL=@npool,PROPOSED_INC=@nprop,FI[/EMAIL]
ELD1=@nf1,FIELD2=@nf2,FIELD3=@nf3 where EMPLOYEEID=" & empid
Dim cmd As SqlCommand
cmd = New SqlCommand(ins, SqlConnection1)
cmd.Parameters.Add("@nname", newname)
cmd.Parameters.Add("@ntitle", newtitle)
cmd.Parameters.Add("@ndate", newdate)
cmd.Parameters.Add("@ntarget", newtarget)
cmd.Parameters.Add("@nbase", newbase)
cmd.Parameters.Add("@nmulti", newmulti)
cmd.Parameters.Add("@npool", newpool)
cmd.Parameters.Add("@nprop", newprop)
cmd.Parameters.Add("@nf1", newf1)
cmd.Parameters.Add("@nf2", newf2)
cmd.Parameters.Add("@nf3", newf2)
cmd.ExecuteNonQuery()
cmd.Connection.Close()
DataGrid1.EditItemIndex = -1
FillDataGrid()
and FillDatagrid is the following,
VB.NET:
Private Sub FillDataGrid()
If Not Me.IsPostBack Then
DataGrid1.DataBind()
End If
End Sub
Can someone tell where am i doing wrong. It is very urgent and i need the solution before noon today. I appreaciate your help.
Thanks,
Simran
Last edited by a moderator: