|
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. 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. Also I had to spell P-A-R-S-E as Parsse because the forum detected it as an unallowed word
Below is my code, any help would be greatly appreciated:
<%@ Page Language="vb" Debug="true" Trace="False"%>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Web" %>
<script runat="server">
Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)
` Determine id to Update
If Not (Request.Params("Uid") Is Nothing) Then
Uid = Int32.Parsse(Request.Params("Uid"))
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("SupID")) = False Then
SupID.Text = CType(dr("SupID"), String)
End If
cc1.SelectedIndex = CType(dr("cc1"), 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("going to sql 2000 db;")
Dim myCommand As New SqlCommand("Getrb", myConnection)
` Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
` Add Parameters to SPROC
Dim parameterUid As New SqlParameter("@Uid", 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("Getrb", myConnection)
Dim myCommand As New SqlCommand("Addrb", myConnection)
` Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
` Add Parameters
Dim parameterUid As New SqlParameter("@Uid", SqlDbType.Int, 8)
parameterUid.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterUid)
Dim parameterSupID As New SqlParameter("@SupID", SqlDbType.NVarChar, 200)
parameterSupID.Value = SupID
myCommand.Parameters.Add(parameterSupID)
Dim parametercc1 As New SqlParameter("@cc1", 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("server=VERTIS08; user id=vsmd; password=vsmd; database=VSMD;")
Dim myCommand As New SqlCommand("Updaterb", myConnection)
` Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
` Add Parameters to SPROC
Dim parameterUid As New SqlParameter("@Uid", SqlDbType.Int, 4)
parameterUid.Value = Uid
myCommand.Parameters.Add(parameterUid)
Dim parameterSupID As New SqlParameter("@SupID", SqlDbType.NVarChar, 200)
parameterSupID.Value = SupID
myCommand.Parameters.Add(parameterSupID)
Dim parametercc1 As New SqlParameter("@cc1", 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 = "Record Added"
Else
`Update record
Updaterb(Uid,SupID.Text,cc1.SelectedIndex)
EditTxt.Text = "Record Updated"
End If
End If
End Sub
</script>
<HTML>
<HEAD>
<TITLE>Radio Button</TITLE>
</head>
<body bgcolor=#CDC8B1 scroll=no>
<form runat="server">
<p align="right">
<asp:Button id="btnUpdate" onclick="UpdateBtn_Click" runat="server" Text="Update"></asp:Button>
<input type=button onclick="Javascript:winClose();" name=JKJH value=Close>
</p><asp:textbox ID="SupID" runat="server" Width="250px"></asp:textbox>
<asp:radiobuttonlist ID="cc1" runat="server" textalignment="right" selectindex="<%#cc1.SelectedIndex%>">
<asp:listitem id="option1" runat="server" />
<asp:listitem id="option2" runat="server" />
</asp:radiobuttonlist>
</form>
<div style=`border:1pt inset color:#3D59AB` id=messageLine><asp:literal id="editTxt" runat="server"/>
</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
|
|
|
|
|
|
|
// |