|
I have finally solved my dropdownlist databinding issue....Next prolem. I now have a selected value. That value correpsopnds to a row of data. How do I access this data?
Here is my code.
Thanks in advance
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
DropDownList DropList = new DropDownList();<br />
<br />
DropList.ID = "AirportList";<br />
DropList.AutoPostBack = true;<br />
<br />
DropList.SelectedIndexChanged += <br />
new EventHandler(this.Selection_Change);<br />
<br />
oleDbDataAdapter1.Fill(dsn_AirportList1,"tblAirport");<br />
Session["DSN_AirportList"] = dsn_AirportList1;<br />
DropList.DataSource = dsn_AirportList1;<br />
DropList.DataTextField = "AirportName";<br />
DropList.DataBind();<br />
if(!IsPostBack)<br />
{ <br />
DropList.SelectedIndex = 0;<br />
}<br />
PlaceHolder1.Controls.Add(DropList);<br />
}<br />
#region Web Form Designer generated code<br />
override protected void OnInit(EventArgs e)<br />
{<br />
InitializeComponent();<br />
base.OnInit(e);<br />
}<br />
<br />
private void InitializeComponent()<br />
{ <br />
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();<br />
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();<br />
this.oleDbConnection2 = new System.Data.OleDb.OleDbConnection();<br />
this.dsn_AirportList1 = new DSN_AirportList();<br />
((System.ComponentModel.ISupportInitialize)(this.dsn_AirportList1)).BeginInit();<br />
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;<br />
this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {<br />
new System.Data.Common.DataTableMapping("Table", "tblAirport", new System.Data.Common.DataColumnMapping[] {<br />
new System.Data.Common.DataColumnMapping("AirportCode", "AirportCode"),<br />
new System.Data.Common.DataColumnMapping("AirportID", "AirportID"),<br />
new System.Data.Common.DataColumnMapping("AirportName", "AirportName"),<br />
new System.Data.Common.DataColumnMapping("City", "City"),<br />
new System.Data.Common.DataColumnMapping("Latitude", "Latitude"),<br />
new System.Data.Common.DataColumnMapping("Longitude", "Longitude"),<br />
new System.Data.Common.DataColumnMapping("State", "State")})});<br />
this.oleDbSelectCommand1.CommandText = "SELECT AirportCode, AirportID, AirportName, City, Latitude, Longitude, State FROM" +<br />
" tblAirport";<br />
this.oleDbSelectCommand1.Connection = this.oleDbConnection2;<br />
this.oleDbConnection2.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=""D:\MGDevelopment\DropDownList2\DB\simdac_be.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";<br />
this.dsn_AirportList1.DataSetName = "DSN_AirportList";<br />
this.dsn_AirportList1.Locale = new System.Globalization.CultureInfo("en-US");<br />
this.Load += new System.EventHandler(this.Page_Load);<br />
((System.ComponentModel.ISupportInitialize)(this.dsn_AirportList1)).EndInit();<br />
<br />
}<br />
#endregion<br />
<br />
void Selection_Change(Object sender, EventArgs e)<br />
{<br />
DropDownList DropList = <br />
(DropDownList)PlaceHolder1.FindControl("AirportList"); <br />
<br />
string xxx=DropList.SelectedItem.Value;<br />
int yy=DropList.Items.Count;<br />
}<br />
|
|
|
|
|
I figured it out......Too easy!
|
|
|
|
|
How you you list the branches of say, System.Windows.Forms ???
(I want to make code-completion in a .cs text editor)
-ProtoArmor
|
|
|
|
|
You can always look in System.Reflection for hints. You should also realize that assemblies and namespaces are not tied together. There might be more stuff in a given namspace that are in assemblies that aren't loaded.
|
|
|
|
|
From my AUT project, here's how I get the classes in an assembly for a particular namespace:
private ClassCollection GetClassCollection()
{
ClassCollection classCollection=new ClassCollection();
Type[] types=assembly.GetTypes();
foreach (Type type in types)
{
if (type.IsClass)
{
MethodInfo[] methods=type.GetMethods(Options.BindingFlags);
foreach (MethodInfo methodInfo in methods)
{
if (methodInfo.DeclaringType.Namespace==namespaceName)
{
string className=StringHelpers.RightOfRightmostOf(methodInfo.DeclaringType.FullName, '.');
Type t=methodInfo.DeclaringType;
classCollection.Add(className, new ClassItem(assembly, namespaceName, className, type));
}
}
}
}
return classCollection;
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Hello all,
I am writing a client for a remote windows service using C#.
I first instantiate the remote object ...
Type t = Type.GetTypeFromProgID(progId, serverName);
APPLib.IApp obj = (APPLib.IApp)Activator.CreateInstance(type);
Then I use the method and it works great ..
obj.SomeMethod();
But if I unplug the network cable between the object creation and its use, I get a 0x800706BF COMException (The remote procedure call failed.) which is expected. The problem I have is after I reconnect the network cable and then try to recover by calling the Type.GetTypeFromProgID() and Activator.CreateInstance(type) methods, I repeatedly get "The remote procedure call failed." COM Exceptions in the Activator.CreateInstance() call. I can even start another instance of my client that connects to the remote server just fine while this instance is still throwing execptions.
Any suggestions on how to recover gracefully?
Thank you,
Bob
|
|
|
|
|
use try/catch
|
|
|
|
|
Thank you for the suggestion and I apologize for not being clearer. I do use try/catch blocks. I am attempting to implement some retry logic to handle the occasional network glitch. The CreateObject() method in the code below wraps the Type.GetTypeFromProgID() and Activator.CreateInstance() calls. The CreateObject() method is also the method I call to intially create the remote object (crudq in this code).
What I do to create this problem is set a breakpoint on the crudq.DatabaseQuery call. When the breakpoint is reached (and the remote object crudq is successfully created), I unplug the network cable and hit F10 to execute the call. The crudq.DatabaseQuery() throws a RPC_S_CALL_FAILED COMException. I then plug the network cable back in then F10 through the code. Every call to CreateObject() throws a RPC_S_CALL_FAILED COMException when it calls Activator.CreateInstance().
Below is the code:
<br />
public void DatabaseQuery(string databaseName, int instance, Object input, Object filter, ref Object output, ref int result)<br />
{<br />
bool retry = true;<br />
int count = 0;<br />
int r = 0;<br />
Object o;<br />
do<br />
{<br />
try<br />
{<br />
crudq.DatabaseQuery(databaseName, instance, timeout, input, filter, out o, out r);<br />
retry = false;<br />
result = r;<br />
output = o;<br />
}<br />
catch(COMException c)<br />
{<br />
if (count < retryAttempts && (c.ErrorCode == RPC_S_CALL_FAILED || c.ErrorCode == RPC_S_SERVER_UNAVAILABLE))<br />
{<br />
x.Info("DatabaseQuery: Retry count: " + count.ToString() + ", Exception: " + c.Message);<br />
Thread.Sleep(delayBetweenRetry);<br />
<br />
Object obj;<br />
try<br />
{<br />
CreateObject(progID, server, out obj);<br />
crudq = (AMSLib.ICRUDQ)obj;<br />
}<br />
catch<br />
{<br />
}<br />
++count;<br />
}<br />
else<br />
{<br />
x.Error("DatabaseQuery: Exception caught: " + c.Message, c);<br />
throw;<br />
}<br />
}<br />
catch(Exception e)<br />
{<br />
x.Error("DatabaseQuery: Exception caught: " + e.Message, e);<br />
throw;<br />
}<br />
}<br />
while(retry);<br />
}<br />
Thank you,
Bob
|
|
|
|
|
Hi
does anyone know where i can get a class to read ID3v1 and v2 tags in mp3-files?
And how can i read the information in wma files?
Hope you can help me
Thanks
|
|
|
|
|
Hmmm
I found a class for MP3 Ids, both V1 and V2.
I havent been able to take a look at them closely but in the following URL you can get the code and a working Demo.
URL:
http://www.csharphelp.com/archives/archive226.html[^]
About WMA, i dont know.
Greetings!
|
|
|
|
|
I'm trying to iterate through a Dictionary and remove some of the elements according to some criterion. I get an InvalidOperationException that says: "Collection was modified; enumeration operation may not execute."
IDictionary<IPAddress, DateTime> peers = new Dictionary<IPAddress, DateTime>();
foreach (KeyValuePair<IPAddress, DateTime> peer in peers) {
if (peer.Value < DateTime.Now) {
peers.Remove(peer.Key);
}
}
The condition given is not the actual condition (as it would remove all elements from the collection).
|
|
|
|
|
Foreach should not be used to change the contents of a collection. Use a for-loop instead.
www.troschuetz.de
|
|
|
|
|
But it isn't possible to go through a Dictionary with a for-loop. The only iteration tool available is the IEnumerator and that's what the foreach contruct uses!
|
|
|
|
|
Considering this restriction, I think the simpelst way to avoid the error would be to collect the keys of all elements that should be removed and then remove them after finishing the enumeration.
www.troschuetz.de
|
|
|
|
|
That's what I did, was just wondering if there was a better way to do it.
|
|
|
|
|
No, you are NOT.
You are looping over the Dictionary and removing entries at the same time.
Shove them into an ArrayList and remove them AFTER completion of the foreach-loop.
Cheers
Sid
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Perhaps I wasn't clear enough. I've got a working version that does as you described. I thought the solution was ugly and wondered if there was a better one.
|
|
|
|
|
That's not true.
You can get the Keys collection and iterate over it with a for loop:
for (int i=0; i<myDict.Keys.Count; i++)
{
object o = myDict[Keys[i]];
} Regards,
mav
|
|
|
|
|
I think that this would be more inefficient than iterating using a foreach-loop as I'm interested in removing entries according to a condition applied to the value, not the key. The foreach-loop uses the collections enumerator which probably is the most effecient way to iterate through the collection as it makes use of the collections underlying implementation. But I could be wrong though.
Please post some code that would does the same things as the one I posted if you have the time.
|
|
|
|
|
If you have runtime considerations I don't know which version is faster.
But I just wanted to counter the statement that you can't iterate over a Dictionary with a for loop.
Your original code would look something like this:
for (int i=0; i<peers.Keys.Count; i++)
{
DateTime time = peers[peers.Keys[i]] as DateTime;
if (time < DateTime.Now)
{
peers.Remove(peers.Keys[i]);
i--;
}
} (written from memory, may contain typos/bugs).
Regards,
mav
|
|
|
|
|
My statement was perhaps a bit to general. I meant that it wasn't possible to iterate through the key-value pairs with a for loop. It is, just as you say, possible to iterate through the keys and values on their own.
|
|
|
|
|
I created a class inherited from TextBox and to add it into my forms I just added Windows TextBox objects then modified the code created by VS by modifying the type to my own textbox class.
This worked fine for a while; however, all of sudded all my controls dissapeared. This must have happened because I emptied the folder that contained my custom TextBox.
So to prevent this from happening in the future, what is the right way of adding custom controls to windows forms so it doesn't wipe them out automatically?
I also have some classes inherited from "System.Windows.Forms.UserControl" and the same problem happened a while ago, so before I start creating a form with a whole bunch of my custom controls I would rather figure out how to add them the right way to prevent them from disappearing.
Please don't tell me I have to add my controls to the GAC. That would be a pain. Reason is that a while ago I added some dll's to the GAC and when I wanted to step through my code, it wouldn't step in and I couldn't figure out the reason. Finally I removed my dll from GAC and then I could go in debug mode. Maybe I did something wrong here as well, so please feel free to comment.
|
|
|
|
|
Hi;
To add your custom control on to the toolbox in VS do the following steps:
1: Create a directory somewhere on your system where you will place your custom control dll's in. Do not delete this directory or it contents. If you do the controls will not show up in your Toolbox or any forms you put them on VS.Net.
2: Go to the Toolbox and select the tab you want the control to show up on, or create a new tab by right clicking on the Toolbox and select Add Tab from the menu and fill in the tab name at the bottom of the Toolbox and press enter key. Then click on the tab.
3: Right click on the Toolbox and select Add/Remove Toolbox Items...
4: In the Customize Toolbox dialog make sure that the .Net Framework Components tab is selected and then click on the Browse... button.
5: Now navigate to the directory you created in step 1 and double click on the custom control dll you want to add.
6: Your control should now have a check mark next to it and its version number at the bottom of the page. click the OK button.
Now any time you need your control just go to the toolbox and drag it on to the form.
I hope this has been of some help.
-Fernando Soto
|
|
|
|
|
Thanks, your detailed steps sure help.
|
|
|
|
|
Hi,
I have just installed MS SQL 2005 Express for testing purpose but a unabe t gn.. what user id and passwrd should use?
Many Thanks,
Jassim Rahma
|
|
|
|