Hello Everyone,

I need help in this issue and if I solve it, I will solve all of my problems in the web program I am building. I have a list of cateogries where I can do 2 things: Start a new list under that category (list of sub categories) and there is no issue with that and second is edit the name of that category and this is where I have the issue. You see When I click on a certain category (no matter its position) I can locate that category via its ID number. Therefore, I direct the user to a page let's say, Edit.aspx?ID=##, in that file, I build my form and my issue is I can retrieve the value of the chosen category but I can't place its value inside the following element:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

to update the database when the user clicks on the save button. Is there a way to update the asp.net textbox via calling a sub and returning a value? You see it is important to do it this way because When having many elements in a single form, it would be a hastle and black work to build the asp.net controls in a Sub / Function which by the way, it did not work out for me also. I tried the below but it did work. It gave the actual code as the text value. Maybe you can understand my direction through the below code:

Sub that reads from the database by getting the ID through request.querystring (a classic ASP command), and then return the value of the category. Inside my aspx file, I set the following

<asp:TextBox ID="TextBox1" runat="server" text="<%=ID%>></asp:TextBox>

Just above it I do the following

ID = callingsub()

I tried using ID = CallingSub() in the asp classic tags

ID = CallingSub()

But I used the TextBox1.Text = ID inside the aspx.vb file inside my function / sub. Below is what I mean:

Suppliers.aspx file:




<asp:TextBox ID="EditItem" CssClass="InputText" runat="server" direction="rtl"></asp:TextBox>

Suppliers.aspx.vb file:

Public  Sub DisplaySupplier()

Dim Item As String = ""
Dim Id As Integer
Dim mainId As Integer
Dim Level As Integer

Id = Request.QueryString("Id")
mainId = Request.QueryString("mainId")
Level = Request.QueryString("Level")

If mainId.ToString Is Nothing Then
mainId = 0
End If

If Level.ToString Is Nothing Then
Level = 1
Level = Level + 1
End If

Dim dr As System.Data.SqlClient.SqlDataReader

Dim sql As String = "SELECT * FROM tblSuppliers WHERE Id = " & Id

Dim SQLConn As SqlConnection = New SqlConnection(SetSQLConnection())



Dim command As New SqlCommand(sql, SQLConn)
dr = command.ExecuteReader

While dr.Read()

  Item = dr("Item").ToString()
  EditItem.Text = Item

End While


End Try


dr = Nothing
SQLConn = Nothing

End Sub

Am I missing something here? This also does not work for the password field.



7 Years
Discussion Span
Last Post by jbisono

another way to retrieve just one value from the database is using the executescalar method.
in that case you will add after this line

Dim commando As New SqlCommand(sql,SQLConn)
EditItem.Text = commando.ExecuteScalar().ToString()

ExecuteScalar return an object. so maybe you want to check if that object is not null first.
Try that.

Edited by jbisono: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.