473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Binding object method to Dataview.. Not understanding List<GENERIC> ..

Pardon my being a total C# noob.

I'm trying to take apart the dotNet Time Tracker dotNet C# starterkit
sample application and replicate a part of the code.

At a high level, I have a very simple SQL server table and stored
procedure which I have no problems binding from directly from an
ASP.NET control...

Table BOOK
name varchar(50)
phone varchar(10)
ALTER procedure "jcp1"
@name varchar(50) AS
SELECT phone FROM book where name = @name

What I'm trying to do is return a dataview given a textbox value passed
to to the stored procedure, but using C# method and List<like they do
in the sample Ap. Eventough I might not need to, I'm trying to use a
generic List but I'm just not getting it.

I reverted my code to the closest working revision, the below code is
apparently fetching the correct row, however I am unable to see or list
no other other items except LENGTH of the returning field when
configuring the control in the UI . I suspect this is because I'm using
List<stringand not List<whaterver>.

The Dataview source is the method getphone() with a where clause of a
textbox = name
The idea being, if I enter "Jason" in the texbox, the dataview would
list phone with name "Jason"..
I'm sure there is more right than wrong with the below - I just taking
shots in the dark at this point.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Collections;
using System.Text;
/// <summary>
/// Summary description for jcp
/// </summary>
///

public class book
{
private string name;
private string phone;

}

public class jcp
{

private delegate void TGenerateListFromReader<T>(SqlDataReader
returnData, ref List<TtempList);
/**** connection string */
public static string ConnectionString =
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
public static List<stringGetPhone(string name) {
SqlCommand sqlCmd = new SqlCommand();
AddParamToSQLCmd(sqlCmd, "@name", SqlDbType.NText, 50,
ParameterDirection.Input, name);
SetCommandType(sqlCmd, CommandType.StoredProcedure, "jcp1");
List<stringuserList = new List<string>();
TExecuteReaderCmd<string>(sqlCmd, TGeneratephone<string>, ref
userList);
return (userList);
}

#region SQL HELPER

protected static void AddParamToSQLCmd(SqlCommand sqlCmd,
string paramId,
SqlDbType sqlType,
int paramSize,
ParameterDirection paramDirection,
object paramvalue)
{

if (sqlCmd == null)
throw (new ArgumentNullException("sqlCmd"));
if (paramId == string.Empty)
throw (new ArgumentOutOfRangeException("paramId"));

SqlParameter newSqlParam = new SqlParameter();
newSqlParam.ParameterName = paramId;
newSqlParam.SqlDbType = sqlType;
newSqlParam.Direction = paramDirection;

if (paramSize 0)
newSqlParam.Size = paramSize;

if (paramvalue != null)
newSqlParam.Value = paramvalue;

sqlCmd.Parameters.Add(newSqlParam);
}

private static void SetCommandType(SqlCommand sqlCmd, CommandType
cmdType, string cmdText)
{
sqlCmd.CommandType = cmdType;
sqlCmd.CommandText = cmdText;
}

private static void ExecuteScalarCmd(SqlCommand sqlCmd)
{
if (ConnectionString == string.Empty)
throw (new
ArgumentOutOfRangeException("ConnectionString"));

if (sqlCmd == null)
throw (new ArgumentNullException("sqlCmd"));

using (SqlConnection cn = new SqlConnection(ConnectionString))
{
sqlCmd.Connection = cn;
cn.Open();
sqlCmd.ExecuteScalar();
}
}

private static void TExecuteReaderCmd<T>(SqlCommand sqlCmd,
TGenerateListFromReader<Tgcfr, ref List<TList)
{
if (ConnectionString == string.Empty)
throw (new
ArgumentOutOfRangeException("ConnectionString"));

if (sqlCmd == null)
throw (new ArgumentNullException("sqlCmd"));

using (SqlConnection cn = new SqlConnection(ConnectionString))
{
sqlCmd.Connection = cn;

cn.Open();

gcfr(sqlCmd.ExecuteReader(), ref List);
}
}

private static void TGeneratephone<T>(SqlDataReader returnData, ref
List<stringphoneList)
{
while (returnData.Read())
{
string phone = (string)returnData["phone"];
phoneList.Add(phone);
}
}

#endregion SQL HELPER
}

Thank you for ANY help or information.

Sep 18 '06 #1
0 3466

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Scottie_do | last post by:
I'm considering switching to C# and using VS2005, but I'd like to know if I can have a list of values at runtime and then specify (at runtime) what it's value type is. For example, I would have...
3
by: Varangian | last post by:
Hello, there I have a problem with regards to System.Collections.Generic.List<T> I need to pass a class with implements an interface - TestClass : IPerson I put this class in a...
6
by: Jeff.Boeker | last post by:
I'm learning a lesson in how I need to be more specific :) In C++ I can resize a vector and it will allocate memory and it will call the default constructor if necessary (or I can supply an...
2
by: per9000 | last post by:
Hi, *background* I want a class containing an int (a list of sets of integer). This should be hidden for the user and he/she should be able to insert his/her favourite data structure so to be a...
7
by: Abhishek | last post by:
Hi I am using a generic list in my program to have a list of objects stored. I want to compare all the objects in this list with object of another class and find all the objects which meet the...
9
by: Stephan Steiner | last post by:
Hi I seem to have a bit of trouble understanding one bit of how generics work: In C#, every class automatically derives from object, and inherits a bunch of properties (i.e. ToString()). Thus,...
12
by: Mark S. | last post by:
Hello, The app in question is lives on a Windows 2003 server with .NET 2.0 running IIS 6. The page of the app in question processes 2000 get requests a second during peak loads. The app uses...
4
by: Peted | last post by:
I have the following code public enum pdfFlags { PFD_DRAW_TO_WINDOW, PFD_DRAW_TO_BITMAP, PFD_SUPPORT_GDI, PFD_SUPPORT_OPENGL, PFD_GENERIC_ACCELERATED, PFD_GENERIC_FORMAT,
0
by: DR | last post by:
System.Collections.Generic.List<intmyList = new System.Collections.Generic.List<int>(100); Does this preallocate 100 integers? Also, is there any way to preallocate an array of objects all at...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.