|
Hi all. I am not well experienced with the Settings feature on the new VS, and the way it accesses\creates App.config files. But here is a simple one
<configuration>
<configsections>
<sectiongroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<applicationsettings>
<qualitycenter.properties.settings>
<setting name="SqlServerName" serializeas="String">
<value>
<setting name="SqlUserName" serializeas="String">
<value>
<setting name="SqlPassword" serializeas="String">
<value>
You notice that the setting SqlServerName value is empty at the time I built the dll. The dll is a COM application with public interfaces to invoke different windows (Forms). I manually changed the <appname>.dll.config file and specified a name for the SqlServerName. When I invoke my COM app, It does not seem that it is reading my app settings from the config file because the value of the sqlservername is still null. Any one has any ideas about what I am doing wrong.
thx
|
|
|
|
|
I guess it stiped out the sample, but here it is again
<applicationSettings>
<QualityCenter.Properties.Settings>
<setting name="SqlServerName" serializeAs="String">
<value />
</setting>
<setting name="SqlUserName" serializeAs="String">
<value />
</setting>
<setting name="SqlPassword" serializeAs="String">
<value />
</setting>
</QualityCenter.Properties.Settings>
</applicationSettings>
|
|
|
|
|
Hi everyone.
I am on the LAST beginner tutorial on MSDN in C#. I have a couple questions.
I am adding to my database with the code :
this.cd_tableTableAdapter.Insert(cdName, cdDescription, image);
this.cd_tableTableAdapter.Fill(this.cdTrackerDataSet.cd_table);
This is SUPPOSED to write to my database and of course it shows up while the app is running, but it NEVER writes it to the database.
I thought I remember from a previous tutorial that I had to do an actual UPDATE on the database to make sure it got written. Is this correct? Can someone help me permanently write this info to my dbase?
Thanks!
|
|
|
|
|
There are many ways to write data to the db:
With SqlDataAdapter:
FETCH DATA:
SqlConnection con = new SqlConnection( connectionstring);
SqlCommand command = new SqlCommand("select* from table", con);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet set = new DataSet();
adapter.Fill(set);
CHANGE DATA:
//get row to change
DataRow row = set.Select("Columnx = 1");
row("Columnx") = 2;
//Write to DB
adapter.Update(set);
//commit dataset
set.AcceptChanges();
INSERT NEW ROW:
DataRow newrow = set.Tables[0].NewRow();
newrow("Columnx") = x;
newrow("Columny") = y;
set.Tables[0].Rows.Add(newrow);
adapter.Update(set);
set.AcceptChanges();
Connection does not have to be opened nor closed when using adapter.
You can also use direct SQL like so..
SqlConnection con = new SqlConnection( connectionstring);
SqlCommand command = new SqlCommand("insert into table values(1,2) ", con);
con.Open();
command.ExecuteNonQuery();
con.Close();
|
|
|
|
|
I want to make a typewriter like program (you know, writes a string 1 letter at a time), so I tried to use a timer but the timer elapsed event has to be static, so then you don't have access to global variables \=
I tried this but it doesn't work:
<br />
public string myString = "hello all";<br />
public int i=0;<br />
static void Main(string[] args)<br />
{<br />
System.Timers.Timer t = new System.Timers.Timer(200);<br />
t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);<br />
t.Start();<br />
Console.Read();<br />
}<br />
<br />
static void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)<br />
{<br />
Program mypr = new Program();<br />
Console.Write(mypr.getString());<br />
mypr.addToI();<br />
}<br />
public string getString()<br />
{<br />
if (i < myString.Length)<br />
return myString[i].ToString();<br />
else<br />
return null;<br />
}<br />
public void addToI()<br />
{<br />
i++;<br />
}<br />
because it creates a new instance of "Program" each time the timer is elapsed =\
so how can I do it?
|
|
|
|
|
Hi,
Hope I didn't missunderstood your problem.
Why not having a static string :
public static string myString = "hello all";
so you have no need of creating a program object
Marc
PS: ElapsedEventHandler do not require a static method
try:
t.Elapsed += new System.Timers.ElapsedEventHandler(this.MyNonStaticMethod);
|
|
|
|
|
Hi.
I'm new to .NET, and I'm writing a logging service that uses .NET remoting. The idea is that the service publishes an EventProcessor object that clients can access via .NET Remoting, passing it DiagnosticEvent objects for processing.
I've altered the main program for the service slightly so that I can run it more easily as a "regular" application during debugging. I have an assembly that contains the "diagnostics" classes that do the work, the service app itself, and a test client app that lets you create a DiagnosticEvent and "dispatch" it.
The problem is that I'm getting errors telling me that the DiagnosticEvent object which I'm passing to the remote object is "not marked for serialization" -- even though it is. When I try adding a function that takes a TestObject, expecting the same error, I then get an exception about "unable to load for deserialization."
I'm clearly missing something basic.
One more little hitch is that I've been wrestling with static initialization of the remote object. It's a singleton class, and it seems that I get messed up if the server application instantiates the class before remote applications get a chance to. But perhaps that's for another post.
Can someone help me clear up my serialization issues? Here's some of the code:
The object I'm passing to the remote object is declared as:
[Serializable]
public class DiagnosticEvent : ISimObject
{ . . . }
...and so is my TestObject:
[Serializable]
public class TestObject
{
public int m_Int;
public string m_String;
}
Here's the code where the remote object is served up:
private static TcpChannel Publish()
{
TcpChannel channel = null;
if (channel == null)
{
// Create an instance of a channel
channel = new TcpChannel(8080);
ChannelServices.RegisterChannel(channel, false);
}
// Register as an available service with the name GEDiag
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(GESim.Diagnostics.EventProcessor),
"GEDiag",
WellKnownObjectMode.Singleton);
return channel;
}
Here's the code where the client connects to the remote object:
private void ConnectToEventProcessor()
{
// Create a channel for communicating w/ a remote object
// Notice no port is specified -- because we're the client.
if (null == s_Channel)
{
s_Channel = new TcpChannel();
ChannelServices.RegisterChannel(s_Channel, false);
}
if (null == m_RemoteEventProcessor)
{
// Create an instance of the remote object
m_RemoteEventProcessor =
(EventProcessor)Activator.GetObject(
typeof(EventProcessor),
"tcp://T00472343:8080/GEDiag");
}
}
...and finally, the code where the remote object is exercised -- both with a TestObject and with the actual DiagnosticEvent object. Neither work, for different reasons:
TestObject testObject = new TestObject();
testObject.m_Int = 45;
testObject.m_String = "Testing 123...";
int i = m_RemoteEventProcessor.Test(testObject);
m_RemoteEventProcessor.EnqueueEvent(theEvent);
I'd be happy to send the solution (I've scultped it down to something minimal).
Thanks, in advance.
Just Mike
|
|
|
|
|
Your problem could be that one of the properties/fields in your DiagnosticEvent class isn't marked as serializable.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hmmm. Well, I've used serialization before, and I've always only declared the class itself. Also, I just tried tagging member variables, and even accessors, with [Serializable] and it won't compile. Am I understanding you correctly?
|
|
|
|
|
Not quite - but you are on the right lines. If one of the fields/properties is not inherently serializable then you can't serialize that class (without explicitly marking the field as not serializable).
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
OK, now I'm quite confused. I understand that one can mark certain members as "nonserialized." But I didn't think I had to mark members at all if I do want them serialized. In fact, when I try to, I get: " Attribute 'System.Serializable' is not valid on this declaration type. It is valid on 'class, struct, enum, delegate' declarations only."
What do you mean by "inherently serializable," then?
Here's my entire DiagnosticEvent class (stripped of comments and such):
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Runtime.Remoting;<br />
using System.Runtime.Remoting.Channels;<br />
using System.Runtime.Remoting.Channels.Tcp;<br />
using GESim.Core;<br />
<br />
namespace GESim.Diagnostics<br />
{<br />
[Serializable]<br />
public class TestObject<br />
{<br />
public int m_Int;<br />
public string m_String;<br />
}<br />
<br />
public enum Severity { <br />
UNDEFINED = 0,<br />
INFORMATIONAL = 1,<br />
WARNING = 2,<br />
NONFATAL_ERROR = 3,<br />
FATAL_ERROR = 4 }; <br />
<br />
[Serializable]<br />
public class DiagnosticEvent : ISimObject<br />
{<br />
private bool m_IsDebug = false;<br />
private Severity m_Severity = Severity.UNDEFINED;<br />
private DateTime m_CreationTime = DateTime.Now;<br />
private string m_Message = string.Empty;<br />
<br />
public DiagnosticEvent(Severity severity)<br />
{<br />
m_Severity = severity;<br />
}<br />
<br />
public DiagnosticEvent(string message, Severity severity)<br />
{<br />
m_Message = message;<br />
m_Severity = severity;<br />
}<br />
<br />
public DiagnosticEvent(string message, Severity severity, bool isDebug)<br />
{<br />
m_Message = message;<br />
m_Severity = severity;<br />
m_IsDebug = isDebug;<br />
}<br />
<br />
public bool IsDebug<br />
{<br />
get { return m_IsDebug; }<br />
set { m_IsDebug = value; }<br />
}<br />
<br />
public Severity Severity<br />
{<br />
get { return m_Severity; }<br />
set { m_Severity = value; }<br />
}<br />
<br />
public DateTime CreationTime<br />
{<br />
get { return m_CreationTime; }<br />
set { m_CreationTime = value; }<br />
}<br />
<br />
public string Message<br />
{<br />
get { return m_Message; }<br />
set { m_Message = value; }<br />
}<br />
<br />
public string GetSqlInsertCommand()<br />
{<br />
string theCommand =<br />
string.Format(<br />
Resource.SQL_INSERTVALUES_DIAGEVENT,<br />
m_CreationTime.ToString(Resource.SQL_DATETIME_FORMAT),<br />
m_IsDebug ? 1 : 0,<br />
(int)m_Severity,<br />
m_Message);<br />
<br />
return theCommand;<br />
}<br />
}<br />
}<br />
|
|
|
|
|
I think you may have slightly missed my point. Suppose that you use a third party library in your application and the developers didn't mark their classes as Serializable. Now, you include a reference to one of these classes through a property. This cannot be serialized because the third party class isn't serializable. To get round this, you would mark the member variable as NonSerializable.
Now, to the matter in had. I loaded this class in and successfully serialized it (granted only to XML). I guess that your problem must be elsewhere.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Oh, OK. Yes, I understand that part.
Thanks for trying my class. As for whether your news is good or bad... I'm not sure. I'm starting from scratch with a brand new solution...
|
|
|
|
|
Hi Guys is it possible to do something along the lines of
<br />
for (i=0; i < (namearray.length); i++) { string[] namearray[i] }<br />
I'm wanting to create a number of arrays dynamically depending on how many variables get loaded into my namearray, I would also like the arrays to be called whatever the variable in the array is called.
so for example:
<br />
namearray[1] = Tom namearray[2] = Dick namearray[3] = harry<br />
I would like my arrays then to be called
Tom, Dick and Harry
The namearray variables are loaded from a csv and are therefore dynamic, so thats what the for loops is for and the variables are taken from CSV headers and to make my coding a lot easier I'd like them to be called the same as the CSV headers in the file.
Hope this makes some sense
Anyhelp appreciated,
cheers
Tom
|
|
|
|
|
Hello,
I would dynamicaly create a 'System.Collections.Hashtable' and add a 'System.Collections.Specialized.StringCollection' instance.
As Key you can use the Names you got from the file.
All the best,
Martin
|
|
|
|
|
Just for future reference a guy on another forum came up with the answer,
string[] arrayNames = new string[fieldCount]; // arraySize = headers.Length?
for(int i = 0; i < headers.Length; i++) {
arrayNames[i] = headers[i];
}
This appears to create arrays named with whats in my headers array, and the length of the data in my data arrays.
Cheers
Tom
|
|
|
|
|
|
Tom,
I'm afraid I don't really understand your question, but have you looked at using jagged arrays?
Cheers,
Vikram.
"But nowadays, it means nothing. Features are never frozen, development keeps happening, bugs never get fixed, and documentation is something you might find on wikipedia."
- Marc Clifton on betas. Join the CP group at NationStates. Password: byalmightybob
|
|
|
|
|
I have a Usercontrol with a public property List<int> Links
List<int> Links= new List<int>();
public List<int> LinkLabels
{
get { return Links; }
set { Links = value; }
}
Now when i put it on a dialog and open the properties dialog in design mode i can click the (...) button and it opens up the add items to collection dialog and i can add a few int(s) to the collection but when i click ok and open it up again all entered values are gone
if i set a breakpoint at the set function then the value is empty
any help will be greatly appreciated
-Thanks
|
|
|
|
|
can you explain it more with code?
When You are adding items? in runtime or during the design?
My small attempt...
|
|
|
|
|
during design time through the public properties (in properties tab)
C++ where friends have access to your private members !
|
|
|
|
|
add
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
to the property being exported
C++ where friends have access to your private members !
|
|
|
|
|
hi all,
i want to update my existing windows application using click once,
here i fallowed the necessory steps, but i couldn't control some statements,
i could check wether the application is of clickonce by ApplicationDeployment.IsNetworkDeployed property, but i couldn't able to manage code
i mean i am checking updates manually if its already the higher version i need to desplay in messagebox which i couldn't using the below code...
<b>if (ApplicationDeployment.IsNetworkDeployed)</b> {
ApplicationDeployment CurrentDeploy = ApplicationDeployment.CurrentDeployment;
CurrentDeploy.CheckForUpdateCompleted += OnCheckForUpdateCompleted;
CurrentDeploy.UpdateCompleted += OnUpdateCompleted;
//OnCheckForUpdateCompleted(sender,e);
//OnUpdateCompleted(sender,e);
if (CurrentDeploy.CheckForUpdate())
{
CurrentDeploy.Update();
DialogResult dr = MessageBox.Show("Update Downloaded,Restart the Application", "Application Update", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
Application.Restart();
}
}
}
else <b>if(!ApplicationDeployment.IsNetworkDeployed)</b>
{
<b>MessageBox.Show("No Updates are available", "UpDate Info");</b>
}
}
prashanth,
s/w Engineer,
Syfnosys.
|
|
|
|
|
Has anyone used this family of controls in anger, esp. the Tree/List widget? I'm especially keen to have multi-column, multi-selection, drag/drop with print/print-preview abilities - and this seems to fit nicely. Anyone got any war stories to share or other products to suggest?
Thx++
Whoops. Here's the URL:
http://www.devexpress.com/Products/NET/WinForms/XtraTreeList/Index.xml
|
|
|
|
|
Does anybody know if it is possible to use generics
in an attribute ?
Example: (what I would like to do)
class MyClass <T>{
[MyAttribute(T == typeof(ClassCase1) ? "Case1" : "Case2")]
private object MyProp{
get{...}
set{...}
}
}
Thanks
May u have a bug free day...
|
|
|
|