Do I need to count the listbox items and refer to the chosen one???!!!

  • Hello

    I have an SQL 2005 Express table with the fields DocID (Unique), DocTitle, DocPath and DocSubmitter.

    I am using a Web Form to insert records, I can do the Title (textbox) and Path (FileUpload) no problem.

    The submitter is linked via a submitterID relationship to another table, submitters. So it will be expecting a number (1-30) not a name as listed in a dropdown list on the web form.

    How do I update this field???

    Thanks, Mark

  • are you looking for e.g.

    Me

    .myrelationddl.SelectedValue.ToString

     

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • More specifically, you need to make the field for the submitter id into a Dropdown List (ddl) instead of a textbox.  You bind the target table's (the one you are trying to update) submitterid to the selected value of the dropdown box.  The dropdown box needs to be populated using an appropriate datasource (e.g. SQL Data Source with the query "SELECT submitterID, submitterName FROM submitter, order by submitterName" - making the submitterName the display value and submitterid the value for the ddl).

    What this does is:

    (1) Cause the dropdown box to comeup showing the name of the submitter (if any) whose ID is in the bound table.column

    (2) Permit the user to select a different/new submitter and populate the target table's submitterID with the corresponding submitterID.

  • Thanks guys, worked it out from that. Now having problems with Security.

    Connection to databse failed! I'm using Windows Authentication.

    Dim

    dbName As String = "KnowledgeBase_dat.mdf"

    Dim cst As String = "Data Source=.\sqlexpress;" & "Integrated Security=TRUE;" & "AttachDBFileName=" & dbName

    Dim cnn1 As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(cst)

    Dim cmd1 As New Data.SqlClient.SqlCommand

    Try

    cnn1.Open()

    cmd1.CommandText = "INSERT Documents " _

    & "(DocTitle, DocPath, SubmitterID, CategoryID) VALUES " _

    & "(Me.TextBox1.Text, Me.FileUpload1.FileName, Me.DropDownList2.SelectedValue, Me.DropDownList1.SelectedValue)"

    cmd1.Connection = cnn1

    Catch ex As Exception

    ConnectionStatusLabel.Text = ("Connection to Database Failed")

    End Try

    It throws the exception! I altered the code from a book. Not sure why the cmd1.Connection = cnn1 appears after the insert? (Is that why it's failing or is it my security setup)?

    Mark

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply