Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radiobuttonlist update

Status
Not open for further replies.

mlongwa

IS-IT--Management
Joined
May 29, 2002
Messages
2
Location
US
Hello I am new to .net in all aspects. I thought I was getting it until I tried to update a radiobuttonlist and ran into multiple errors. Below is my code, any help would be greatly appreciated. I can get data but anytime I add or update data it just resets the radiobuttonlist to 0. I have removed my connection string, but I can connect to the db fine:

<%@ Page Language=&quot;vb&quot; Debug=&quot;true&quot; Trace=&quot;False&quot;%>
<%@ import Namespace=&quot;System&quot; %>
<%@ import Namespace=&quot;System.Data&quot; %>
<%@ import Namespace=&quot;System.Data.SqlClient&quot; %>
<%@ import Namespace=&quot;System.Web&quot; %>

<script runat=&quot;server&quot;>

Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)

' Determine id to Update
If Not (Request.Params(&quot;Uid&quot;) Is Nothing) Then
Uid = Int32.Parse(Request.Params(&quot;Uid&quot;))
End If

' If the page is being requested the first time
If Page.IsPostBack = False Then

If Uid <> 0 Then

' Obtain a single row

Dim dr As SqlDataReader = Getrb(Uid)

' Load first row into DataReader
dr.Read()

If IsDBNull(DR.Item(&quot;SupID&quot;)) = False Then
SupID.Text = CType(dr(&quot;SupID&quot;), String)
End If

cc1.SelectedIndex = CType(dr(&quot;cc1&quot;), Integer)



' Close the datareader
dr.Close()

End If
End If

End Sub


Public Function Getrb(ByVal Uid As Integer) As SqlDataReader

' Create Instance of Connection and Command Object
Dim MyConnection As New SqlConnection(&quot;going to sql 2000 db;&quot;)
Dim myCommand As New SqlCommand(&quot;Getrb&quot;, myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim parameterUid As New SqlParameter(&quot;@Uid&quot;, SqlDbType.Int, 4)
parameterUid.Value = Uid
myCommand.Parameters.Add(parameterUid)

' Execute the command
myConnection.Open()
Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

' Return the datareader
Return result

End Function

Public Function Addrb(Uid As Integer, ByVal SupID As String, ByVal cc1 As integer) As Integer

' Create Instance of Connection and Command Object
Dim MyConnection As New SqlConnection(&quot;Getrb&quot;, myConnection)
Dim myCommand As New SqlCommand(&quot;Addrb&quot;, myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters
Dim parameterUid As New SqlParameter(&quot;@Uid&quot;, SqlDbType.Int, 8)
parameterUid.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterUid)

Dim parameterSupID As New SqlParameter(&quot;@SupID&quot;, SqlDbType.NVarChar, 200)
parameterSupID.Value = SupID
myCommand.Parameters.Add(parameterSupID)

Dim parametercc1 As New SqlParameter(&quot;@cc1&quot;, SqlDbType.int, 4)
parametercc1.Value = cc1
myCommand.Parameters.Add(parametercc1)

End Function
Public Sub Updaterb(ByVal Uid As Integer, ByVal SupID As String, ByVal cc1 As integer)

' Create Instance of Connection and Command Object
Dim MyConnection As New SqlConnection(&quot;going to sql 2000 db;&quot;)
Dim myCommand As New SqlCommand(&quot;Updaterb&quot;, myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim parameterUid As New SqlParameter(&quot;@Uid&quot;, SqlDbType.Int, 4)
parameterUid.Value = Uid
myCommand.Parameters.Add(parameterUid)

Dim parameterSupID As New SqlParameter(&quot;@SupID&quot;, SqlDbType.NVarChar, 200)
parameterSupID.Value = SupID
myCommand.Parameters.Add(parameterSupID)

Dim parametercc1 As New SqlParameter(&quot;@cc1&quot;, SqlDbType.int, 4)
parametercc1.Value = cc1
myCommand.Parameters.Add(parametercc1)

End Sub

Private Uid As Integer = 0



'****************************************************************
'
' The UpdateBtn_Click event handler.
'
'****************************************************************

Sub UpdateBtn_Click(sender As Object, ByVal e As EventArgs)

' Only Update if the Entered Data is Valid
If Not Page.IsPostBack Then
'Dim
If Uid = 0 Then

'Add record
Addrb(Uid,SupID.Text,cc1.SelectedIndex)

EditTxt.Text = &quot;Record Added&quot;

Else

'Update record
Updaterb(Uid,SupID.Text,cc1.SelectedIndex)

EditTxt.Text = &quot;Record Updated&quot;

End If


End If

End Sub



</script>

<HTML>
<HEAD>
<TITLE>Radio Button</TITLE>



</head>
<body bgcolor=#CDC8B1 scroll=no>
<form runat=&quot;server&quot;>

<p align=&quot;right&quot;>
<asp:Button id=&quot;btnUpdate&quot; onclick=&quot;UpdateBtn_Click&quot; runat=&quot;server&quot; Text=&quot;Update&quot;></asp:Button>
&nbsp;
<input type=button onclick=&quot;Javascript:winClose();&quot; name=JKJH value=Close>
</p><asp:textbox ID=&quot;SupID&quot; runat=&quot;server&quot; Width=&quot;250px&quot;></asp:textbox>

<asp:radiobuttonlist ID=&quot;cc1&quot; runat=&quot;server&quot; textalignment=&quot;right&quot; selectindex=&quot;<%#cc1.SelectedIndex%>&quot;>
<asp:listitem id=&quot;option1&quot; runat=&quot;server&quot; />
<asp:listitem id=&quot;option2&quot; runat=&quot;server&quot; />
</asp:radiobuttonlist>

</form>
<div style='border:1pt inset color:#3D59AB' id=messageLine><asp:literal id=&quot;editTxt&quot; runat=&quot;server&quot;/>
</div>
</body>
</html>

stored procedures:

getrb

CREATE PROCEDURE Getrb
(
@Uid int
)
AS

SELECT
Uid,
SupID,
cc1

FROM
rb

where Uid = @Uid
GO



Addrb


CREATE PROCEDURE Addrb
(
@SupID nvarchar(200),
@cc1 nvarchar(200),
@Uid int OUTPUT

)
AS

INSERT INTO rb
(


SupID,
cc1
)

VALUES
(

@SupID,
@cc1

)

SELECT
@Uid = @@Identity
GO

CREATE PROCEDURE Updaterb
(

@Uid int,
@SupID nvarchar(200),
@cc1 int

)

AS

UPDATE
rb

SET

SupID=@SupID,
cc1=@cc1

WHERE
Uid = @Uid
GO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top