|
I think you just copied and pasted you homework assignment. Try coding it yourself FIRST, then ask specific questions about any C# code issues you run into.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
No, this is not a homework question.
This is one of the sample questions in one of my books that I'm using to study for the 70-316.
The book said that you use the dataset constructor. However, i saw this question online, and the answer online said to use the namespace property.
I thought the parameter passed to the data set consructor was just the name of the data set. I went to MSDN and looked at the namespace property but I couldnt find anything that it set the root element.
I dont have any coding access right now, and was just wondering if anyone can help me out.
Thank you
|
|
|
|
|
Flack wrote:
The book said that you use the dataset constructor. However, i saw this question online, and the answer online said to use the namespace property.
A namespace can not directly contain a field or method without a class . A namespace provides a way to define scope, thus allowing globally unique types.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Flack wrote:
This is one of the sample questions in one of my books that I'm using to study for the 70-316.
Further proof that certifications don't mean much, huh?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
If you read the .NET Framework SDK (which will teach you more than a book - especially since certifications typically prove nothing), in order to name the DataSet you pass either the name (which will be the document element, or "root element") to the constructor or instantiate with the default constructor and assign the DataSetName property after its instantiated. Namespace allows you to declare an XML namespace for the DataSet XML document or fragment.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Can anyone tell me how can I read from/write to the parallel port in VC#?
Thanx
ahmedadel
|
|
|
|
|
You can't do it directly because Windows abstract the hardware from your app. You'll also not find any support for such operations in the .NET BCL. You'll have to use a specially written .DLL to do the actual writing and reading of ports for you. See http://www.logix4u.net[^] for the .DLL and example code in various languages. IF there is not C# example, you'll have to translate either C++ or VB code to C#.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
NTPort. It has C# examples also.
/\ |_ E X E GG
|
|
|
|
|
i would like to trap the windows state changes when your computer goes into standbye, hibernate, etc., which i believe are defined by ACPI as states S1-S5. can i trap these messages from .NET?
|
|
|
|
|
Implement the IMessageFilter and add your implementation using Application.AddMessageFilter . Each main form is sent the WM_QUERYENDSESSION (0x0011) and WM_ENDSESSION (0x0016) in succession. You can handle these in your IMessageFilter implementation. See the Platform SDK documentation at http://msdn.microsoft.com/library[^] for more information about these messages and what you can (and can't) return (i.e., assign to the Message.Result property), as well as the possible values for the Message.WParam and Message.LParam properties. These values are defined in winuser.h in the Platform SDK, which is downloadable from http://msdn.microsoft.com/platformsdk[^] and is installed by default with Visual Studio.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hmm... maybe i misunderstood your suggestion, but what i am specfically trying to do is have a winform running on a computer, and when that computer goes into stanby or hibernate mode, i want to be able to catch this state change and perform actions based on which state it changed into right before the system goes off into this state.
|
|
|
|
|
And I told you exactly how to do that. You can also use the Microsoft.Win32.SystemEvents.SessionEnding and Microsoft.Win32.SystemEvents.SessionEnded events, but then your code will not be portable to other platforms.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am using CultureInfo objects in my application to ensure that the correct localisation is loaded from a set of resources, however I have found that certain cultures are not supported, for example Celtic languages such as "GD" (Scots Gaelic), "CY" (Welsh) or "GA" (Irish Gaelic).
For the moment, I want just to be able to use the CultureInfo object to pull the correct resources from Satellite assemblies. However every route I look at requires a CultureInfo object to be presented somewhere.
Is there any way to extend the CultureInfo so that I can have it accepting cultures that .NET does not intrinsically support? Or is there anyway to pull the resources easily from the correct satellite assembly without having to write lots of addional code mimicking what the existing system does?
CultureInfo does appear to be open to derivation, however I've not seen and indication that it would achieve anything. Can anyone point me in the direction of some links that would get me started on this?
Any help would be appreciated. Thanks.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
You could extend CultureInfo hypothetically, but you'll have to override every virtual member. The CultureInfo ctor won't accept an unrecognized LCID or name.
Getting satellite resources isn't that hard, however. The problem is overriding ResourceManager so that you can tell it which resource assembly to grab for unsupported CultureInfo s.
I have written such code fairly easily (all the power you need is pretty much defined on the Assembly class, like GetSatelliteAssembly ) and have extended the ResourceManager to do so. Either way, you're going to have to write some code. Since the current ResourceManager works with CultureInfo class, you may have the best luck extending CultureInfo and overriding everything necessary (basically, keep your own look-up table of information; currently, localization in .NET P/Invokes some of this functionality from native APIs).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
I have written such code fairly easily
Rather than re-invent the wheel, do you care to share?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
This code gets a manifest resource stream (identitied by the const StreamResource ) from a satellite assembly. Unfortunately, you'll still need a valid CultureInfo (sorry, it's been a while since I wrote this; it might still help, though):
public static Stream GetZipResourceStream(CultureInfo culture)
{
Assembly asm = typeof(SiteBuilder).Assembly;
CultureInfo neutral = GetNeutralResourcesLanguage(asm);
if (culture == null || !culture.Equals(neutral))
{
Version v = GetSatelliteContractVersion(asm);
if (v == null) v = asm.GetName().Version;
try
{
asm = asm.GetSatelliteAssembly(culture, v);
}
catch
{
try
{
asm = asm.GetSatelliteAssembly(culture.Parent, v);
}
catch {}
}
}
Stream s = asm.GetManifestResourceStream(SiteResource);
return s;
}
internal static CultureInfo GetNeutralResourcesLanguage(Assembly a)
{
if (a == null) throw new ArgumentNullException("a");
if (a == typeof(object).Assembly)
return CultureInfo.InvariantCulture;
NeutralResourcesLanguageAttribute[] attrs =
(NeutralResourcesLanguageAttribute[])
a.GetCustomAttributes(typeof(NeutralResourcesLanguageAttribute), false);
if (attrs.Length == 0) return CultureInfo.InvariantCulture;
try
{
return new CultureInfo(attrs[0].CultureName);
}
catch (ThreadAbortException)
{
throw;
}
catch (Exception ex)
{
throw new ArgumentException(
BLR.FormatString("InvalidNeutralResourcesLanguageCulture",
a.ToString(), attrs[0].CultureName), "a", ex);
}
}
internal static Version GetSatelliteContractVersion(Assembly a)
{
if (a == null) throw new ArgumentNullException("a");
if (a == typeof(object).Assembly)
return null;
SatelliteContractVersionAttribute[] attrs =
(SatelliteContractVersionAttribute[])
a.GetCustomAttributes(typeof(SatelliteContractVersionAttribute), false);
if (attrs.Length == 0) return null;
try
{
return new Version(attrs[0].Version);
}
catch (Exception ex)
{
throw new ArgumentException(
BLR.FormatString("InvalidSatelliteContractVersion",
a.ToString(), attrs[0].Version), "a", ex);
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
Unfortunately, you'll still need a valid CultureInfo
Can't have everything!
Thanks for your help.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
Hello!
This is my first post. I have a little problem. I have build a small Windows Form application. It has 1 form and a couple of buttons and textboxes and a datagrid. I want to build a simple search. So, if I type a letter "D" in a textbox, I want in a DataGrid a list of all names that starts with a "D". If I type further a letter "a" and "v" for example, I would get a "Dave" names for example.
This is what I programmed so far:
static void FilterData()<br />
{<br />
<br />
try<br />
{<br />
<br />
string strFilter = "SELECT Avtosalon.Ime," + <br />
"Naslov.Ulica, Naslov.PostnaSt, Naslov.Kraj, Avtosalon.Telefon," + <br />
"Avtosalon.EPosta, Avtosalon.Vodja, Avtosalon.OdpiralniCas " +<br />
"FROM Avtosalon INNER JOIN Naslov ON Avtosalon.IDNaslov = Naslov.IDNaslov ";<br />
<br />
if (!MyForm.txtIme.Focused)<br />
{<br />
strFilter = strFilter + "WHERE Avtosalon.Ime LIKE '" + MyForm.txtIme.Text + "%'";<br />
if (MyForm.txtUlica.Focused)<br />
strFilter = strFilter + " AND Naslov.Ulica LIKE '" + MyForm.txtUlica.Text + "%'";<br />
else if (MyForm.txtPostnaSt.Focused)<br />
strFilter = strFilter + " AND Naslov.PostnaSt LIKE '" + MyForm.txtPostnaSt.Text + "%'";<br />
else if (MyForm.txtKraj.Focused)<br />
strFilter = strFilter + " AND Naslov.Kraj LIKE '" + MyForm.txtKraj.Text + "%'";<br />
else if (MyForm.txtTelefon.Focused)<br />
strFilter = strFilter + " AND Avtosalon.Telefon LIKE '" + MyForm.txtTelefon.Text + "%'";<br />
else if (MyForm.txtEPosta.Focused)<br />
strFilter = strFilter + " AND Avtosalon.EPosta LIKE '" + MyForm.txtEPosta.Text + "%'";<br />
else if (MyForm.txtVodja.Focused)<br />
strFilter = strFilter + " AND Avtosalon.Vodja LIKE '" + MyForm.txtVodja.Text + "%'";<br />
else if (MyForm.txtOdpiralniCas.Focused)<br />
strFilter = strFilter + " AND Avtosalon.OdpiralniCas LIKE '" + MyForm.txtOdpiralniCas.Text + "%'";<br />
} <br />
<br />
MyDataSet = new DataSet();<br />
MyDataAdapter = new SqlDataAdapter(strFilter,conn); <br />
MyDataAdapter.Fill(MyDataSet,"Avtosalon"); <br />
MyDataAdapter.Dispose();<br />
MyForm.BeginInvoke(CallDataBindToDataGrid);<br />
strFilter = null;<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message.ToString());<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
static void DataBindToDataGrid()<br />
{<br />
<br />
MyForm.gridAvtosalon.DataMember = "Avtosalon"; <br />
MyForm.gridAvtosalon.DataSource = MyDataSet;<br />
MyDataSet = null;<br />
MyDataAdapter = null;<br />
}
private void txtIme_TextChanged(object sender, System.EventArgs e)<br />
{<br />
try<br />
{<br />
UpdateThread = new Thread(UpdateThreadStart);<br />
UpdateThread.Name = "Update Thread";<br />
UpdateThread.IsBackground = true;<br />
UpdateThread.Start();<br />
<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message.ToString());<br />
}<br />
<br />
}
So, the problem is, when I type in a textbox, I get an error message "There is an open DataReader associated with this
Connection wich must be closed first" and I don't use DataReader at all. Could you help me, couse I study this now for
days and I can't see where is a problem. Thank in advance.
|
|
|
|
|
There are several problems here. With every character you type, TextChanged is fired. Since your updating your DataSet in the background using the same SqlConnection , then all those threads are trying to open separate connections to the same resource (the SqlConnection instance) at once. Even using separate connection resources isn't a good way, because this code is grossly inefficient (with each character typed, the database is queried). Instead, either use a button that filters the results when clicked, or use the LostFocus event or something for a TextBox .
Also, you're relying on input from the user to fill the WHERE clause. This is extremely bad. Think of what would happen if I typed the following into a TextBox :
A';DELETE FROM Avtosalon WHERE Ime LIKE ' That would delete all records in your Actosalon table - and even worse is possible if your DB security isn't tight (I could drop the master table, for example). The important thing when writing software is NEVER TRUST USER INPUT - no matter who the user is (they could inadvertently do something bad). And don't think they won't know your database structure: I could use the IL Disassembler (ildasm.exe) that comes with the SDK (free) or some other disassembler/decompiler and easily find out how to attack your code and database.
Instead, do what you're supposed to use with ADO.NET: parameterized queries. Read about the SqlParameter class and the SqlCommand.Parameters property in the .NET Framework SDK for lots of information and example source code. Using this not only makes for easier to read code, but eliminates the need for you to make sure strings are escaped (which is one thing that allows me to type what I did above) and it automatically performs checks for common attacks, this decreasing the attack surface.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hello every one,
can i integrate my Menu with Windows Shell ContextMenu (the one which pops up whenever we right click mouse) using C# classes.
Problem is, I want to do it without using Interop (Com) simply because i dont have pre-requiste COM knowledge.
suggestion of ne kind are welcomed
thanx.
|
|
|
|
|
goooooooogle wrote:
Problem is, I want to do it without using Interop (Com) simply because i dont have pre-requiste COM knowledge. suggestion of ne kind are welcomed
If you don't want to learn, why are you bothering asking. There are a whole slew of articles here on both COM Interop and Shell programming within C#. I would suggest you read those and when you get stuck either check out MSDN[^], post a question to the articles author on the forum within the article or post a question here.
- Nick Parker My Blog | My Articles
|
|
|
|
|
goooooooogle wrote:
Problem is, I want to do it without using Interop (Com) simply because i dont have pre-requiste COM knowledge
Impossible. Windows is still COM based so either you do it in COM or you don't do it all.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How would I go about changing the number of spaces a tab uses when the user presses Tab on his/her keyboard? Thanks in advance.
Happy Programming and may God Bless!
"Your coding practices might be buggy, but your code is always right."
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
From my experience, I dont think u can, I digged alot thru the Win API but couldnt find anything...
top secret xacc-ide 0.0.1
|
|
|
|
|
See the documentation[^] for the RichTextBox.SelectionTabs property. This is the same as sending the EM_SETPARAFORMAT with a PARAFORMAT2 structure in native code with the cTabCount and rgzTabs fields assigned.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|