Solved

Displaying and Passing values from a dataadapter

Posted on 2006-11-27
3
207 Views
Last Modified: 2010-04-23
I'm hoping this is an easy one but I'm just overlooking something simple.


I have a data adapter a that pulls to values from the database.    One is a complete name of a document the other is a reference number.  I'm displaying the document name in a drop down for the users to select - it works fine, but when they select it, I want to pass the associated reference number  instead of the documents name.

code:

'sqlGetIMGDocsAdapter
        '
        Me.sqlGetIMGDocsAdapter.SelectCommand = Me.SqlSelectCommand41
        Me.sqlGetIMGDocsAdapter.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "sp_GetIMGDocs", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("IMGDOC_Code", "IMGDOC_Code"), New System.Data.Common.DataColumnMapping("DOC_Name", "DOC_Name")})})
        '
        'SqlSelectCommand41
        '
        Me.SqlSelectCommand41.CommandText = "[sp_GetIMGDocs]"
        Me.SqlSelectCommand41.CommandType = System.Data.CommandType.StoredProcedure
        Me.SqlSelectCommand41.Connection = Me.SqlConnection3
        Me.SqlSelectCommand41.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
        '

Then I just do a fill

  Ds_IMGDoc221.Clear()
        sqlGetIMGDocsAdapter.Fill(Ds_IMGDoc221)




Suggestions?

Thanks in advance
0
Comment
Question by:TimSweet220
  • 2
3 Comments
 
LVL 10

Assisted Solution

by:gangwisch
gangwisch earned 100 total points
ID: 18020488
the best suggestion i have is to databind the dataset from the dataadapter then do:
datagridview1.columns("Reference_Number").visible=false
when they select it datagridview1.item("Reference_Number",currentrowindex).value will equal what you need

Good Luck
0
 
LVL 5

Assisted Solution

by:proten
proten earned 400 total points
ID: 18021902
Why not set the text to the datafield you wish to display, and the value to the datafield value you wish to return

i.e.

dropdownlist1.DataSource = ds.tables(0)
dropdownlist1.DataTextField = "DataDisplay"
dropdownlist1.DataValueField = "DataValue"

This will send back the value that is transparent to the user when selected but display the display field to the user.
0
 
LVL 5

Accepted Solution

by:
proten earned 400 total points
ID: 18021919
ds is the DataSet with the data from your dataadapter

DataDisplay and DataValue are the names of the database fields returned,.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now