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

Tech-Archive recommends: Fix windows errors by optimizing your registry



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<string> and 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<T> tempList);
/**** connection string */
public static string ConnectionString =
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;


public static List<string> GetPhone(string name) {
SqlCommand sqlCmd = new SqlCommand();
AddParamToSQLCmd(sqlCmd, "@name", SqlDbType.NText, 50,
ParameterDirection.Input, name);
SetCommandType(sqlCmd, CommandType.StoredProcedure, "jcp1");
List<string> userList = 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<T> gcfr, ref List<T> List)
{
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<string> phoneList)
{
while (returnData.Read())
{
string phone = (string)returnData["phone"];
phoneList.Add(phone);
}
}

#endregion SQL HELPER
}

Thank you for ANY help or information.

.



Relevant Pages

  • Kinda new and having trouble with SQL stored procedure
    ... private static string ConnectionString ... protected static void AddParamToSQLCmd(SqlCommand sqlCmd, ... ParameterDirection.Input, contactId); ...
    (microsoft.public.dotnet.framework.adonet)
  • ConcurrentModificationException
    ... public class StudentComparator implements Comparator ... public int compare ... private static void modify ... public Student(String aFirstName, String aLastName, int anId) ...
    (comp.lang.java.help)
  • Performance with reading large numbers of files...
    ... I have a small test application that recurses a directory and adds all the file names to a string collection. ... RecurseDirs, sDiskFiles); ... private static void RecurseDirs ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Generische List in String umwandeln
    ... private const int TestArraySize = 2000; ... private static void TestFrank{ ... Stopwatch sw = Stopwatch.StartNew; ... string a = JoinListAlbert; ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Run-time Error 2342
    ... OpenQuery expects the name of a query, not an SQL string. ... Dim qdfCurr As DAO.QueryDef ... I think my sqlCmd statement is correct, but I have on idea, how can I ...
    (microsoft.public.access.modulesdaovba)