473,503 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datalist- Update Query

I have a datalist within a datagrid and I am having trouble trying to get the
update command working. I am only using the one for the datagrid, but this
should also update the datalist, however when it gets to the section:
strgame_score = game_score1.Text it says Object reference not set to an
instance of an object.

Here is my code, can anyone help?

'-------------------------

' Create an appropriate UPDATE statement

strSQL = "UPDATE tblgame SET game_score = @gamescore WHERE game_id = @game_ID"

objconn.Open()

Dim game_ID, strgame_score As String

Dim Dlgame1 As DataList =
CType(e.Item.Cells(3).FindControl("DLscores_edit") , DataList)

' iterate through the DataList's TextBoxes

Dim dlItem As DataListItem

For Each dlItem In Dlgame1.Items

' reference the TextBox

Dim game_score1 As TextBox = CType(dlItem.FindControl("tbgamescore_edit"),
TextBox)

' Grab the value

strgame_score = game_score1.Text

' Get the title_id from DataKeys

game_ID = Dlgame1.DataKeys(dlItem.ItemIndex).ToString()

' Now, update the parameters

Dim game_scoreParam As New Data.SqlClient.SqlParameter("@game_score",
SqlDbType.Int)

If strgame_score = [String].Empty Then

' we need to insert a NULL

game_scoreParam.Value = DBNull.Value

Else

game_scoreParam.Value = strgame_score

End If

objcmd.Parameters.Add(game_scoreParam)

Dim game_IDParam As New Data.SqlClient.SqlParameter("@game_ID", SqlDbType.Int)

game_IDParam.Value = game_ID

objcmd.Parameters.Add(game_IDParam)

Me.Lbsession.Text = strSQL.ToString

' now, execute the query

objcmd.ExecuteNonQuery()

' Clear the parameters

objcmd.Parameters.Clear()

Next dlItem

objConn.Close() ' close the connection

'---------------

Nov 22 '05 #1
0 1343

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4027
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
2
3419
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
3
10278
by: Mirek Endys | last post by:
I have DataList as part of DataList item. DataList in DataList. The parent DataList working well including Edit command, that shows Edit template and correctly bind the data into edit template...
0
1636
by: Les Caudle | last post by:
I have a menu system composed of a DataList nested inside a DataList. The outer DataList has it's DataSource (composed of a DataSet with two tables linked by a CategoryPagesRelation Relation) set...
1
2651
by: AJ | last post by:
Hi all, With the following code in mind : <asp:DataList ID="dlOne" DataKeyField="myField1" DataSource="<%# GetDataSource1()" Runat="server"> <ItemTemplate> Output Value Here! <asp:DataList...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.