|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using CreateDataReader to get a value from a fieldparameter. But I would like to use the CreateDataReader method, or any other efficient method for user with the graphical dataset designer objects created. I have two examples below, The first is Getting a provider Name from a table, based on the ProvID which returns a string. This is code created using no graphical objects or wizard. The second is Getting an employee name, based on an ID called NUID. I wanted to use CreateDataReader, because the objects that I'm working with ARE generated with the graphical objects in the DataSet designer. For example, I created a stored procedure using the TableAdapter in the dataset designer. I've been trying to construct the same method as the working one, using these graphical (or 'strongly typed?' not sure if this is the term) objects, but it isn't quite working. 'working example Public Shared Function GetProviderName(ByVal ProvID As String) As String Dim drProvider As SqlDataReader Dim conMembers As SqlConnection = MembershipDB.GetMembershipConnection() Dim cmd As New SqlCommand("SELECT ProviderFullName FROM dbo.PROV WHERE ProvID = @ProvID", conMembers) cmd.CommandType = CommandType.Text cmd.Parameters.Add("@ProvID", SqlDbType.NVarChar, 5).Value = ProvID conMembers.Open() drProvider = cmd.ExecuteReader(CommandBehavior.SingleRow) If drProvider.Read Then Return IIf(drProvider("ProviderFullName") Is DBNull.Value, "No Provider", drProvider("ProviderFullName")) Else Return "No Provider" End If conMembers.Close() conMembers.Dispose() conMembers = Nothing End Function 'Help with this example Public Shared Function GetEmployeeNameByNUID(ByVal strNUID As String) As String Dim da As New CIA_DatabaseTableAdapters.CIA_REPORT_CTTableAdapter Dim dt As New DataTable Dim strEmployee As String dt = da.FillEmpNameByNUID(strNUID) strEmployee = dt.CreateDataReader("Employee").ToString() Return strEmployee End Function |
|||||||||||||||||||||||