|
(via Instant C# - let me know how the converted code works for you - your original posted formatting is preserved)
using System;
using System.Data.SqlClient;
using System.Collections;
/////
///// A strongly-typed collection of objects.
/////
internal class SqlParamCollection : ICollection, IList, IEnumerable, ICloneable
{
#region Interfaces
/////
///// Supports type-safe iteration over a .
/////
public interface ISqlParamCollectionEnumerator
{
/////
///// Gets the current element in the collection.
/////
SqlParameter Current {get;}
/////
///// Advances the enumerator to the next element in the collection.
/////
/////
///// The collection was modified after the enumerator was created.
/////
/////
///// true if the enumerator was successfully advanced to the next element
///// false if the enumerator has passed the end of the collection.
/////
bool MoveNext();
/////
///// Sets the enumerator to its initial position, before the first element in the collection.
/////
void Reset();
}
#endregion
private const int DEFAULT_CAPACITY = 15;
#region Implementation (data)
private SqlParameter[] m_array;
private int m_count = 0;
private int m_version = 0;
#endregion
#region Static Wrappers
/////
///// Creates a synchronized (thread-safe) wrapper for a
///// SqlParamCollection instance.
/////
/////
///// An SqlParamCollection wrapper that is synchronized (thread-safe).
/////
public static SqlParamCollection Synchronized(SqlParamCollection list)
{
if (list == null)
{
throw new ArgumentNullException("list");
}
return new SyncSqlParamCollection(list);
}
/////
///// Creates a read-only wrapper for a
///// SqlParamCollection instance.
/////
/////
///// An SqlParamCollection wrapper that is read-only.
/////
public static SqlParamCollection GetReadOnly(SqlParamCollection list)
{
if (list == null)
{
throw new ArgumentNullException("list");
}
return new ReadOnlySqlParamCollection(list);
}
#endregion
#region Construction
/////
///// Initializes a new instance of the SqlParamCollection class
///// that is empty and has the default initial capacity.
/////
public SqlParamCollection()
{
m_array = new SqlParameter[DEFAULT_CAPACITY + 1];
}
/////
///// Initializes a new instance of the SqlParamCollection class
///// that has the specified initial capacity.
/////
/////
///// The number of elements that the new SqlParamCollection is initially capable of storing.
/////
public SqlParamCollection(int capacity)
{
m_array = new SqlParameter[capacity + 1];
}
/////
///// Initializes a new instance of the SqlParamCollection class
///// that contains elements copied from the specified SqlParamCollection.
/////
///// The SqlParamCollection whose elements are copied to the new collection.
public SqlParamCollection(SqlParamCollection c)
{
m_array = new SqlParameter[c.Count + 1];
AddRange(c);
}
/////
///// Initializes a new instance of the SqlParamCollection class
///// that contains elements copied from the specified array.
/////
///// The array whose elements are copied to the new list.
public SqlParamCollection(SqlParameter[] a)
{
m_array = new SqlParameter[a.Length + 1];
AddRange(a);
}
#endregion
#region Operations (type-safe ICollection)
/////
///// Gets the number of elements actually contained in the SqlParamCollection.
/////
public virtual int Count
{
get
{
return m_count;
}
}
/////
///// Copies the entire SqlParamCollection to a one-dimensional
///// array.
/////
///// The one-dimensional array to copy to.
public virtual void CopyTo(SqlParameter[] array)
{
this.CopyTo(array, 0);
}
/////
///// Copies the entire SqlParamCollection to a one-dimensional
///// array, starting at the specified index of the target array.
/////
///// The one-dimensional array to copy to.
///// The zero-based index in at which copying begins.
public virtual void CopyTo(SqlParameter[] array, int start)
{
if (m_count > (array.GetUpperBound(0) + 1 - start))
{
throw new System.ArgumentException("Destination array was not long enough.");
}
System.Array.Copy(m_array, 0, array, start, m_count);
}
/////
///// Gets a value indicating whether access to the collection is synchronized (thread-safe).
/////
///// true if access to the ICollection is synchronized (thread-safe) otherwise, false.
public virtual bool IsSynchronized
{
get
{
return m_array.IsSynchronized;
}
}
/////
///// Gets an object that can be used to synchronize access to the collection.
/////
public virtual object SyncRoot
{
get
{
return m_array.SyncRoot;
}
}
#endregion
#region Operations (type-safe IList)
/////
///// Gets or sets the at the specified index.
/////
///// The zero-based index of the element to get or set.
/////
///// is less than zero
///// -or-
///// is equal to or greater than .
/////
public virtual SqlParameter this[int index]
{
get
{
ValidateIndex(index); //// throws
return m_array[index];
}
set
{
ValidateIndex(index); //// throws
m_version += 1;
m_array[index] = value;
}
}
/////
///// Gets or sets the with the specified key.
/////
///// The name of the element to get or set.
/////
/////
public virtual SqlParameter this[string key]
{
get
{
int index = 0;
index = FindItem(key); //// throws
return m_array[index];
}
set
{
int index = 0;
index = FindItem(key); //// throws
m_version += 1;
m_array[index] = value;
}
}
/////
///// Adds a to the end of the SqlParamCollection.
/////
///// The to be added to the end of the SqlParamCollection.
///// The index at which the value has been added.
public virtual int Add(SqlParameter item)
{
if (m_count == m_array.Length)
{
EnsureCapacity(m_count + 1);
}
m_array[m_count] = item;
m_version += 1;
m_count += 1;
return (m_count - 1);
}
/////
///// Removes all elements from the SqlParamCollection.
/////
public virtual void Clear()
{
m_version += 1;
m_array = new SqlParameter[DEFAULT_CAPACITY + 1];
m_count = 0;
}
/////
///// Creates a shallow copy of the .
/////
public virtual object Clone()
{
SqlParamCollection newColl = new SqlParamCollection(m_count);
Array.Copy(m_array, 0, newColl.m_array, 0, m_count);
newColl.m_count = m_count;
newColl.m_version = m_version;
return newColl;
}
/////
///// Determines whether a given is in the SqlParamCollection.
/////
///// The to check for.
///// true if is found in the SqlParamCollection otherwise, false.
public virtual bool Contains(SqlParameter item)
{
int i = 0;
for (i = 0; i <= (m_count - 1); i++)
{
if (m_array[i].Equals(item))
{
return true;
}
}
return false;
}
/////
///// Returns the zero-based index of the first occurrence of a
///// in the SqlParamCollection.
/////
///// The to locate in the SqlParamCollection.
/////
///// The zero-based index of the first occurrence of
///// in the entire SqlParamCollection, if found otherwise, -1.
/////
public virtual int IndexOf(SqlParameter item)
{
int i = 0;
for (i = 0; i <= (m_count - 1); i++)
{
if (m_array[i].Equals(item))
{
return i;
}
}
return -1;
}
/////
///// Inserts an element into the SqlParamCollection at the specified index.
/////
///// The zero-based index at which should be inserted.
///// The to insert.
/////
///// is less than zero
///// -or-
///// is equal to or greater than .
/////
public virtual void Insert(int index, SqlParameter item)
{
ValidateIndex(index, true); //// throws
if (m_count == m_array.Length)
{
EnsureCapacity(m_count + 1);
}
if (index < m_count)
{
Array.Copy(m_array, index, m_array, index + 1, m_count - index);
}
m_array[index] = item;
m_count += 1;
m_version += 1;
}
/////
///// Removes the first occurrence of a specific from the SqlParamCollection.
/////
///// The to remove from the SqlParamCollection.
/////
///// The specified was not found in the SqlParamCollection.
/////
public virtual void Remove(SqlParameter item)
{
int i = IndexOf(item);
if (i < 0)
{
throw new System.ArgumentException("Cannot remove the specified item because it was not found in the specified Collection.");
}
m_version += 1;
RemoveAt(i);
}
/////
///// Removes the element at the specified index of the SqlParamCollection.
/////
///// The zero-based index of the element to remove.
/////
///// is less than zero
///// -or-
///// is equal to or greater than .
/////
public virtual void RemoveAt(int index)
{
ValidateIndex(index); //// throws
m_count -= 1;
if (index < m_count)
{
Array.Copy(m_array, index + 1, m_array, index, m_count - index);
}
//// We can't set the deleted entry equal to null, because it might be a value type.
//// Instead, we'll create an empty single-element array of the right type and copy it
//// over the entry we want to erase.
SqlParameter[] temp = new SqlParameter[1];
temp[0] = new SqlParameter();
Array.Copy(temp, 0, m_array, m_count, 1);
m_version += 1;
}
/////
///// Gets a value indicating whether the collection has a fixed size.
/////
///// true if the collection has a fixed size otherwise, false. The default is false
public virtual bool IsFixedSize
{
get
{
return false;
}
}
/////
///// gets a value indicating whether the IList is read-only.
/////
///// true if the collection is read-only otherwise, false. The default is false
public virtual bool IsReadOnly
{
get
{
return false;
}
}
#endregion
#region Operations (type-safe IEnumerable)
/////
///// Returns an enumerator that can iterate through the SqlParamCollection.
/////
///// An for the entire SqlParamCollection.
public virtual ISqlParamCollectionEnumerator GetEnumerator()
{
return new Enumerator(this);
}
#endregion
#region Public helpers (just to mimic some nice features of ArrayList)
/////
///// Gets or sets the number of elements the SqlParamCollection can contain.
/////
public virtual int Capacity
{
get
{
return m_array.Length;
}
set
{
if (value < m_count)
{
value = m_count;
}
if (! (value == m_array.Length))
{
if (value > 0)
{
// C# implementation
//Dim temp() As SqlParameter = New SqlParameter(Value-1) {}
//Array.Copy(m_array, temp, m_count)
//m_array = temp
// VB implementation
Array.Resize(ref m_array, value + 1);
}
else
{
m_array = new SqlParameter[DEFAULT_CAPACITY + 1];
}
}
}
}
/////
///// Adds the elements of another SqlParamCollection to the current SqlParamCollection.
/////
///// The SqlParamCollection whose elements should be added to the end of the current SqlParamCollection.
///// The new of the SqlParamCollection.
public virtual int AddRange(SqlParamCollection x)
{
if (m_count + x.Count >= m_array.Length)
{
EnsureCapacity(m_count + x.Count);
}
Array.Copy(x.m_array, 0, m_array, m_count, x.Count);
m_count += x.Count;
m_version += 1;
return m_count;
}
/////
///// Adds the elements of a array to the current SqlParamCollection.
/////
///// The array whose elements should be added to the end of the SqlParamCollection.
///// The new of the SqlParamCollection.
public virtual int AddRange(SqlParameter[] x)
{
if (m_count + x.Length >= m_array.Length)
{
EnsureCapacity(m_count + x.Length);
}
Array.Copy(x, 0, m_array, m_count, x.Length);
m_count += x.Length;
m_version += 1;
return m_count;
}
/////
///// Sets the capacity to the actual number of elements.
/////
public virtual void TrimToSize()
{
this.Capacity = m_count;
}
#endregion
#region Implementation (helpers)
/////
///// is less than zero
///// -or-
///// is equal to or greater than .
/////
private void ValidateIndex(int i)
{
ValidateIndex(i, false);
}
/////
///// is less than zero
///// -or-
///// is equal to or greater than .
/////
private void ValidateIndex(int i, bool allowEqualEnd)
{
int max = 0;
if (allowEqualEnd)
{
max = m_count;
}
else
{
max = m_count - 1;
}
if (i < 0 | i > max)
{
throw new System.ArgumentOutOfRangeException("Index was out of range. Must be non-negative and less than the size of the collection.", (object)1, "Specified argument was out of the range of valid values.");
}
}
/////
///// was not found.
/////
private int FindItem(string key)
{
int index = 0;
for (index = 0; index < m_array.Length; index++)
{
if (m_array[index].ParameterName == key)
{
return index;
}
}
throw new System.ArgumentException("The specified key was not found.");
}
private void EnsureCapacity(int min)
{
int newCapacity = 0;
if (m_array.Length == 0)
{
newCapacity = DEFAULT_CAPACITY;
}
else
{
newCapacity = m_array.Length * 2;
}
if (newCapacity < min)
{
newCapacity = min;
}
this.Capacity = newCapacity;
}
#endregion
#region Implementation (ICollection)
public void CopyTo(Array array, int start)
{
array.Copy(m_array, 0, array, start, m_count);
}
#endregion
#region Implementation (IList)
// Default removed
//ORIGINAL LINE: Property IList_Item(ByVal i As Integer) As Object Implements IList.Item
//INSTANT C# NOTE: C# does not support parameterized properties - the following property has been divided into two methods:
public object GetIList_Item(int i)
{
return (object)(this[i]);
}
public void SetIList_Item(int i, object Value)
{
this[i] = (SqlParameter)Value;
}
public int Add(object x)
{
return this.Add((SqlParameter)x);
}
public bool Contains(object x)
{
return this.Contains((SqlParameter)x);
}
public int IndexOf(object x)
{
return this.IndexOf((SqlParameter)x);
}
public void Insert(int pos, object x)
{
this.Insert(pos, (SqlParameter)x);
}
public void Remove(object x)
{
this.Remove((SqlParameter)x);
}
//Sub RemoveAt(ByVal pos As Integer) Implements IList.RemoveAt
// Me.RemoveAt(pos)
//End Sub
#endregion
#region Implementation (IEnumerable)
IEnumerator IEnumerable.GetEnumerator()
{
return IEnumerable_GetEnumerator();
}
public IEnumerator IEnumerable_GetEnumerator()
{
return (IEnumerator)(this.GetEnumerator());
}
#endregion
#region Nested enumerator class
/////
///// Supports simple iteration over a .
/////
private class Enumerator : IEnumerator, ISqlParamCollectionEnumerator
{
#region Implementation (data)
private SqlParamCollection m_collection;
private int m_index;
private int m_version;
#endregion
#region Construction
/////
///// Initializes a new instance of the Enumerator class.
/////
/////
internal Enumerator(SqlParamCollection tc)
{
m_collection = tc;
m_index = -1;
m_version = tc.m_version;
}
#endregion
#region Operations (type-safe IEnumerator)
/////
///// Gets the current element in the collection.
/////
public SqlParameter Current
{
get
{
return m_collection[m_index];
}
}
/////
///// Advances the enumerator to the next element in the collection.
/////
/////
///// The collection was modified after the enumerator was created.
/////
/////
///// true if the enumerator was successfully advanced to the next element
///// false if the enumerator has passed the end of the collection.
/////
public bool MoveNext()
{
if (! (m_version == m_collection.m_version))
{
throw new System.InvalidOperationException("Collection was modified enumeration operation may not execute.");
}
m_index += 1;
if (m_index < m_collection.Count)
{
return true;
}
else
{
return false;
}
}
/////
///// Sets the enumerator to its initial position, before the first element in the collection.
/////
public void Reset()
{
m_index = -1;
}
#endregion
#region Implementation (IEnumerator)
object IEnumerator.Current
{
get
{
return IEnumerator_Current;
}
}
public object IEnumerator_Current
{
get
{
return (object)this.Current;
}
}
#endregion
}
#endregion
#region Nested Syncronized Wrapper class
private class SyncSqlParamCollection : SqlParamCollection
{
#region Implementation (data)
private SqlParamCollection m_collection;
private object m_root;
#endregion
#region Construction
internal SyncSqlParamCollection(SqlParamCollection list)
{
m_root = list.SyncRoot;
m_collection = list;
}
#endregion
#region Type-safe ICollection
public override void CopyTo(SqlParameter[] array)
{
lock(this.m_root)
{
m_collection.CopyTo(array);
}
}
public override void CopyTo(SqlParameter[] array, int start)
{
lock(this.m_root)
{
m_collection.CopyTo(array, start);
}
}
public override int Count
{
get
{
lock(this.m_root)
{
return m_collection.Count;
}
}
}
public override bool IsSynchronized
{
get
{
return true;
}
}
public override object SyncRoot
{
get
{
return this.m_root;
}
}
#endregion
#region Type-safe IList
public override SqlParameter this[int i]
{
get
{
lock(this.m_root)
{
return m_collection[i];
}
}
set
{
lock(this.m_root)
{
m_collection[i] = value;
}
}
}
public override int Add(SqlParameter x)
{
lock(this.m_root)
{
return m_collection.Add(x);
}
}
public override void Clear()
{
lock(this.m_root)
{
m_collection.Clear();
}
}
public override bool Contains(SqlParameter x)
{
lock(this.m_root)
{
return m_collection.Contains(x);
}
}
public override int IndexOf(SqlParameter x)
{
lock(this.m_root)
{
return m_collection.IndexOf(x);
}
}
public override void Insert(int pos, SqlParameter x)
{
lock(this.m_root)
{
m_collection.Insert(pos, x);
}
}
public override void Remove(SqlParameter x)
{
lock(this.m_root)
{
m_collection.Remove(x);
}
}
public override void RemoveAt(int pos)
{
lock(this.m_root)
{
m_collection.RemoveAt(pos);
}
}
public override bool IsFixedSize
{
get
{
return m_collection.IsFixedSize;
}
}
public override bool IsReadOnly
{
get
{
return m_collection.IsReadOnly;
}
}
#endregion
#region Type-safe IEnumerable
public override ISqlParamCollectionEnumerator GetEnumerator()
{
lock(this.m_root)
{
return m_collection.GetEnumerator();
}
}
#endregion
#region Public Helpers
//// (just to mimic some nice features of ArrayList)
public override int Capacity
{
get
{
lock(this.m_root)
{
return m_collection.Capacity;
}
}
set
{
lock(this.m_root)
{
m_collection.Capacity = value;
}
}
}
public override int AddRange(SqlParamCollection x)
{
lock(this.m_root)
{
return m_collection.AddRange(x);
}
}
public override int AddRange(SqlParameter[] x)
{
lock(this.m_root)
{
return m_collection.AddRange(x);
}
}
#endregion
}
#endregion
#region Nested Read Only Wrapper class
private class ReadOnlySqlParamCollection : SqlParamCollection
{
#region Implementation (data)
private SqlParamCollection m_collection;
#endregion
#region Construction
internal ReadOnlySqlParamCollection(SqlParamCollection list)
{
m_collection = list;
}
#endregion
#region Type-safe ICollection
public override void CopyTo(SqlParameter[] array)
{
m_collection.CopyTo(array);
}
public override void CopyTo(SqlParameter[] array, int start)
{
m_collection.CopyTo(array, start);
}
public override int Count
{
get
{
return m_collection.Count;
}
}
public override bool IsSynchronized
{
get
{
return m_collection.IsSynchronized;
}
}
public override object SyncRoot
{
get
{
return this.m_collection.SyncRoot;
}
}
#endregion
#region Type-safe IList
public override SqlParameter this[int i]
{
get
{
return m_collection[i];
}
set
{
throw new NotSupportedException("This is a Read Only Collection and can not be modified");
}
}
public override int Add(SqlParameter x)
{
throw new NotSupportedException("This is a Read Only Collection and can not be modified");
}
public override void Clear()
{
throw new NotSupportedException("This is a Read Only Collection and can not be modified");
}
public override bool Contains(SqlParameter x)
{
return m_collection.Contains(x);
}
public override int IndexOf(SqlParameter x)
{
return m_collection.IndexOf(x);
}
public override void Insert(int pos, SqlParameter x)
{
throw new NotSupportedException("This is a Read Only Collection and can not be modified");
}
public override void Remove(SqlParameter x)
{
throw new NotSupportedException("This is a Read Only Collection and can not be modified");
}
public override void RemoveAt(int pos)
{
throw new NotSupportedException("This is a Read Only Collection and can not be modified");
}
public override bool IsFixedSize
{
get
{
return true;
}
}
public override bool IsReadOnly
{
get
{
return true;
}
}
#endregion
#region Type-safe IEnumerable
public override ISqlParamCollectionEnumerator GetEnumerator()
{
return m_collection.GetEnumerator();
}
#endregion
#region Public Helpers
//// (just to mimic some nice features of ArrayList)
public override int Capacity
{
get
{
return m_collection.Capacity;
}
set
{
throw new NotSupportedException("This is a Read Only Collection and can not be modified");
}
}
public override int AddRange(SqlParamCollection x)
{
throw new NotSupportedException("This is a Read Only Collection and can not be modified");
}
public override int AddRange(SqlParameter[] x)
{
throw new NotSupportedException("This is a Read Only Collection and can not be modified");
}
#endregion
}
#endregion
}
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter, VB to C++ converter
Instant Python: C# to Python converter, VB to Python converter
|
|
|
|
|
Hello,
I have an ASP.NET page and in its runtime code I am trying to get an
user profile, change it and save it.
It works if I use Profile, which is the profile for the current
authenticated user. But I want to change the profile of another user.
Anyway, I am using:
1 Dim pcProfile As ProfileCommon =
CType(ProfileCommon.Create(Username), ProfileCommon)
2
3 ' Update personal
4 With pcProfile.Personal
5 .Blog = tbBlog.Text
6 .Homepage = tbHomepage.Text
7 .Name = tbName.Text
8 End With
9
10 pcProfile.Save()
This is not working.
What am I doing wrong?
Thanks,
Miguel
|
|
|
|
|
I have a website written in vb.net. The SessionID keep changing everytime i refresh the page
Response.write Session.sessionID
Has anyone got that problem before?
Please help, I am so stress now.
Regards
Nick
P.S I create the another website on the server just to printout the SessionID and it works just fine ( no new value when the page was refresh)
|
|
|
|
|
Hello Nick,
The SessionID keeps changing when no data is assigned to the Session Object. When you assign a value to the Session, the SessionID will not change.
|
|
|
|
|
Hi Can you please tell me about the free / open source blogs available in ASP.Net 2.0
Any database will do.
Please provide links if possible.
Thanks ..
Deepak Surana
|
|
|
|
|
I have a business related intranet site written entirely in asp, note the conspicuous absence of the letter x. I, when I say I in this context I mean our security team, have decided it would be a good idea to handle security through active directory. The aspx code I, I meaning me, have written pulls back a domain and username quite nicely. I would like to do a little database authentication, not a problem, and based on the outcome set a few session variables defining access rights and redirect the user to the old asp pages I have in place.
I have tried both the response.redirect("somepage.asp") and the server.transfer("someotherpage.asp") and they both blow. Can I not get from aspx back into the asp world?
Any help would be appreciated.
|
|
|
|
|
Is the ASP code and .NET code are used in a same project, I mean same Solution??
|
|
|
|
|
I required a web method to be present inside a user control that I have built for my site. The user control contains the new Ajax AutoCompleteExtender which requires use the web method to get it's predictions for the user. I originally built the code straight into a page but it is now required in several other pages so a user control seemed like the way forward. It worked fine in the page but once in a control it seems to go wrong.
Im not sure if there is some sort of permission issues here or what but I would appreicate some help on this. Thanks
|
|
|
|
|
What exactling is messing up when you put it in the user control?
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
Hey. The issue I'm having is the same if
A: I try to put the web method code in a seperate web service file
B: I try to put the web method code in the code behind file of the user control
I get the following Javascript error once you begin to enter text in the textbox itself.
Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"
I'm guessing that for some reason or another the Javascript from within the page cannot find the web method in whatever place it is residing. I am using ServicePath="WebService.asmx" to try and point it in the right direction to no avail.
Any ideas?
|
|
|
|
|
Iam also facing the same issue.Let me know if you have an answer
|
|
|
|
|
hi
how can i install dotnetnuke in my computer?
for install i must "create Virtual Directory in IIS called DotNetNuke which points to the directory where the DotNetNuke.webproj file exists "
i user .net 2.0 i don't have IIS in my machin!
|
|
|
|
|
hi all,
i have to set the Languages (english and spanish)for my web site. i mean my should should work for both the languages. what should i have to do?? i am newbie to .Net.
i think we have to set the culture info (satellite assembly info or something i am not sure, but i don't know exactly. please let me know what should i do??
thanks,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Hi there:
There are a lot of articles out there...here is just one of them SatelliteAssemblies
Enjoy!
<< >>
|
|
|
|
|
Hi,
I'm trying to validate user input on the client side. The values needed for validating the user's input should come from the database where i have a RANGES table. I don't want to expose the user to the table but i want to use the table's values "behind the scene".
Does anybody if and how this can be accomplished?
Thakns a lot in advance.
Snir.
|
|
|
|
|
hi there:
You can use AJAX to do that...
<< >>
|
|
|
|
|
thanks enjoycrack.
Do you reckon it's the only possibility?
|
|
|
|
|
Not at all - write some code to convert the dataset containing the values you want to a JSON string at page load, store it in a hidden field / session, then eval() it at the other end....
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
|
Ahem...[^]
Essentially, it's a text based description of an object.
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
That's most helpfull richard.
Now you're probably gonna sit back and watch me misinterpret what you just said...
Cheers mate.
Snir.
|
|
|
|
|
public static string DataSetToJSON(DataSet ds)
{
string JSON = "{\"Tables\": [";
for (int i = 0; i < ds.Tables.Count; i++)
{
string tmp = DataTableToJSON(ds, "Rows", i);
JSON += tmp;
if (i < ds.Tables.Count - 1)
{
JSON += " , ";
}
}
JSON += "]}";
return JSON;
}
public static string DataTableToJSON(DataSet ds, string dsName, int table)
{
string JSON = "{\"" + dsName + "\" : [";
for (int i = 0; i < ds.Tables[table].Rows.Count; i++)
{
JSON += "{";
for (int j = 0; j < ds.Tables[table].Rows[i].Table.Columns.Count; j++)
{
string columnName = ds.Tables[table].Rows[i].Table.Columns[j].ColumnName;
string columnValue = ds.Tables[table].Rows[i][j].ToString();
columnValue = columnValue.Replace("\r\n", ", ");
JSON += "\"" + columnName + "\": \"" + columnValue + "\"";
if (j != ds.Tables[table].Rows[i].Table.Columns.Count - 1)
{
JSON += " , ";
}
}
JSON += "}";
if (i != ds.Tables[table].Rows.Count - 1)
{
JSON += " , ";
}
}
JSON += "]";
JSON += "}";
return JSON;
}
If it don't work, I don't care
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
string JSON = "{\"" + dsName + "\" : [";
for (int i = 0; i < ds.Tables[table].Rows.Count; i++)
{
//add the row JSON bits...
JSON += "{";
for (int j = 0; j < ds.Tables[table].Rows[i].Table.Columns.Count; j++)
{
string columnName = ds.Tables[table].Rows[i].Table.Columns[j].ColumnName;
string columnValue = ds.Tables[table].Rows[i][j].ToString();
//Replace any crlf's in the column value...
columnValue = columnValue.Replace("\r\n", ", ");
JSON += "\"" + columnName + "\": \"" + columnValue + "\"";
if (j != ds.Tables[table].Rows[i].Table.Columns.Count - 1)
{
JSON += " , ";
}
}
JSON += "}";
if (i != ds.Tables[table].Rows.Count - 1)
{
JSON += " , ";
}
}
JSON += "]";
JSON += "}";
return JSON;
}
If it don't work, I don't care
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
Nope Iam not sure this is the only posibilty...And you can dynamically generate script which depends on values from DB...
Hope you get the idea...
<< >>
|
|
|
|
|
Hi,
Does any one know how to display * character on passord text box?
Thanks a bunch
<< >>
|
|
|
|
|
There should be a property PasswordChar that you insert the character you want.
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|