Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > UPDATE Command problem

Thread Tools

UPDATE Command problem

sushainc sushainc is offline
Junior Member
Join Date: Sep 2009
Posts: 1
My update command was working fine until yesterday but this morning, i don't know what went wrong, it somehow is not reading anything from the TextBox. Each time it would enter the catch saying "error since field is null". PLease help. Below is the snippet of what i've done.

Protected Sub GridView10_update(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)

Dim connString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\OutindexISH.mdf;Integrated Security=True;User Instance=True"
Dim myConnection As SqlConnection = New SqlConnection
myConnection.ConnectionString = connString

' create a data adapter
Dim cmd7 As New SqlCommand("select CustodianTable from " + Request.ServerVariables("AUTH_USER") + " where ProjectName = '" + sname.Text + "'", myConnection)
Dim dr7 As SqlDataReader = cmd7.ExecuteReader
Dim table_name7 As String
table_name7 = "temp"
If (dr7.Read()) Then
table_name7 = dr7("CustodianTable")
End If


Dim CID1 As String
CID1 = GridView10.DataKeys(e.RowIndex).Value

Dim SqlCommand As New SqlCommand("UPDATE " + table_name7 + " SET FirstName = @FirstName, LastName = @LastName, Company = @Company, ContactNumber = @ContactNumber, ContactEmailAddress = @ContactEmailAddress, City = @City, State = @State, Collectdate = @Collectdate, Status = @Status WHERE CID = '" + CID1 + "'", myConnection)

SqlCommand.Parameters.Add("@FirstName", SqlDbType.VarChar)
SqlCommand.Parameters.Add("@LastName", SqlDbType.VarChar)
SqlCommand.Parameters.Add("@Company", SqlDbType.VarChar)
SqlCommand.Parameters.Add("@ContactNumber", SqlDbType.VarChar)
SqlCommand.Parameters.Add("@ContactEmailAddress", SqlDbType.VarChar)
SqlCommand.Parameters.Add("@City", SqlDbType.VarChar)
SqlCommand.Parameters.Add("State", SqlDbType.VarChar)
SqlCommand.Parameters.Add("CollectDate", SqlDbType.VarChar)
SqlCommand.Parameters.Add("@Status", SqlDbType.VarChar)

Dim cols() As String = {"@FirstName", "@LastName", "@Company", "@ContactNumber", "@ContactEmailAddress", "@City", "State", "CollectDate", "@Status"}

Dim Str As String = CType(GridView10.Rows(e.RowIndex).Cells(3).Control s(1), TextBox).Text


Dim i As Integer

Dim colvalue As String
For i = 0 To 8
colvalue = CType(GridView10.Rows(e.RowIndex).Cells(i + 3).Controls(1), TextBox).Text // i+3 since in my gridview first three columns are checkbox, serialnumber and viewdetail

MsgBox(colvalue) //won't take anything from the textboxes

If (i < 9 And colvalue = "") Then
MsgBox("ERROR: Null values not allowed")
Exit Sub
End If

SqlCommand.Parameters(cols(i)).Value = colvalue
Next i


' MsgBox("hi")
' GridView10.EditIndex = -1

Dim Faltu2 As String
Faltu2 = "CID"
If Page.IsPostBack Then
End If


End Sub

<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
<%#DataBinder.Eval(Container.DataItem, "FirstName")%>
<asp:TextBox runat="server" ID = "txtbox1" Width="80%">

This is how other columns are defined.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Update On The Windows Phone 7 Update Update Lawrence D'Oliveiro NZ Computing 2 02-25-2011 08:03 AM
getting problem in SQL update command ASP .Net 1 01-29-2006 06:34 PM
DataGrid - Update Command Event Problem Mr Newbie ASP .Net 1 09-21-2005 06:38 AM
DataGrid - Weird Update Command Problem BW ASP .Net 1 05-27-2005 05:03 PM
How to call javascript when click update command(it Edit command c prakash ASP .Net Web Controls 2 04-11-2005 04:07 AM