|
You should really read the documentation for the SqlDataAdapter in the .NET Framework SDK. You're not using it right, and it's not even necessary here. A DataAdapter is for filling and updating DataSet s using the various command properties. All you're doing in the first example is assigning it. That won't do anything. Just don't use the SqlDataAdapter at all.
The bottom fragment is almost correct, except - again - the SqlDataAdapter isn't necesary. Just instantiate the SqlCommand , assign it to a variable, and execute it.
Since you didn't tell us what the exception was or what it said (always help), I'm betting it's because you're not using parameterized queries, and instead doing the old kludge of string concatenation. If that variable has a quote (either single or double), the SQL statement is invalid. Instead, the correct code - using ADO.NET how it's supposed to be used - is:
SqlConnection conn = new SqlConnection(...);
using (conn)
{
SqlCommand update = new SqlCommand("UPDATE sn_allocatedblocks " +
"SET ab_status = 'Production' WHERE ab_schedule = @schedule " +
"AND ab_schedline = @schedline", conn);
update.Parameters.Add("@schedule", SqlDbType.NVarChar, 20).Value = schedule;
update.Parameters.Add("@schedline", SqlDbType.Int).Value = schedline;
update.ExecuteNonQuery();
} The using block makes sure that even in case of error the connection is closed and disposed (important). Also dispose of objects who's classes implement IDisposable . Change the parameter types to whatever you want (not knowing what they were supposed to be, I just made them up). If that schedline variable and parameter is not a string or date/time type, do not use quotes (quoting a numeric value will result in error as well).
Using parameterized queries signficantly reduces the attack surface (I could easily provide values for your string variables that would terminate the SQL statement and clear-out your master table since you're not checking user input - never trust user input), eliminates the need to properly encode strings (due to single or double quotes screwing up the resultant SQL statement), and allows you to perform bulk updates, inserts, and deletes (since you instantiate the command and add parameter definitions only once; assign the parameters to variables; for each iteration of a loop, change the SqlParameter.Value property for each param and call ExecuteNonQuery ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Does anyone know how to implement a zoom control? like the one in the PrintPreviewControl.
|
|
|
|
|
try it with the Graphics.ScaleTransform method
|
|
|
|
|
Hi all,
Does anyone know why the corners of a box object do not appear to be rounded
(when a report is run) even if they are on the design of the report. I am
using Crystal reports with Dot Net.
|
|
|
|
|
You mean like with a group box or something, like some controls are in windows? Because Crystal Reports doesn't not use the common controls for these types of controls. The common controls are drawn by the theming service (is applicable and started) only when the bindings are redirected to the Common Controls 6 win32 assembly (a side-by-side native DLL). Crystal Reports draws their own controls and doesn't use the Theme API - and why should they? It's a report, not a dialog resource.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi all,
I've been reading up on BHO's and i need to create one, for the past 2 weeks i've had no success getting one to work.
I want to create a sort of a spyware application that gets installed onto a users computer and runs in the background. Then i want this application to log and copy the urls a user visits and the files they downloaded. Once the neccesary information is copied, it then gets sent to a remote database.
I only want to know what code i would need to create a BHO and i would like it to do the following:
Log the url's a user visits
Log the files that a user downloads
Any help would be very much appreciated, if you cannot help me with source code, then references would also be a great help.
Thanx a lot ..!
|
|
|
|
|
You don't really expect anyone here to help you develop Spyware, do you?
Besides, you're getting yourself into lots of trouble by spying on unaware users. Can you spell "lawsuite"?
mav
|
|
|
|
|
|
How embarrassing! My rage let the 'e' slip in!
Always good for a laugh, if only the topic wasn't so serious.
mav
|
|
|
|
|
Hi guys,
I'm a 4th year IT Btech student at the technikon of Port Elizabeth in South Africa.
I would like to create this application with the sole purpose of proving to my lecturers that i am capable of creating the application, so that i can pass the subject and get the neccesary credit to pass my final year.
I assure you that there is no malicious intent what so ever behind the creation of this application, if you do not believe me, i will send you an email from one of my lecturers with the neccessary credentials to prove to you what i say is true.
Besides, its not like i want to copy and steal credit card numbers...
I want to create the application with the sole purpose of logging the url's a user visits and the files he downloads
The end purpose of this application is to create various user profiles and to check what are the most popular sites visited and what are the most common files downloaded
Any help would be very much appreciated
From a student in need ...
Stuggo
|
|
|
|
|
Hey
I'm trying to crate a installation CD for my application.
Things I need to install from the CD
- My application: It's constructed in a way that I only need all items in one folder, no registry enterys, so I only need the "Release" folder copyed to the hard-disk
- .Net 1.1
- DirectX 8.0 or higher
+
A desktop shortcut
How can I do this the easy way? Any examples?
Thanks
Thomas
|
|
|
|
|
In Visual Studio, create a new project. Select a type of Setup and Deployment Projects. Then pick Setup Project or use the Setup Wizard. It's pretty self explanatory.
|
|
|
|
|
That won't even begin to help him. The .NET Framework installation must be bootstrapped. The merge module include in the setup is only there so that BCL assemblies won't be automatically added as local assemblies, nor should any install install them into the GAC (which, if .NET isn't installed prior to the Windows Installer MSI package being installed, there won't even be a GAC). It will not install the .NET Framework. This is also documented in the Visual Studio product documentation.
Additionally, while separate installations can be added as custom actions to be executed as a specific time, it is difficult to say the least to do this with VS.NET's very limited Windows Installer project. Either bootstrapping the DirectX installation (if it needs to be installed) or including it as a separate installation to be executed asynchronously with the main MSI package (typically after installation, without waiting for an execution return) needs to be done.
VS.NET's Windows Installer project is hardly an option. If it is used, more work is required to bootstrap the additional installations needed (especially the .NET Framework).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You need a bootstrapper to do this (at least .NET). There are several examples of this on CodeProject, like Enhanced .NET Bootstrap Setup[^]. If you're using Managed DirectX 9.0b (DirectX for .NET - not just wrappers but written from the ground-up for .NET), you can nest the MSI installation into your MSI package, but VS.NET's Windows Installer project won't allow you do this. You need a professional package developer (like Wise for Windows Installer[^]) or hack it into the MSI package after compiling it using a tool like Orca (available in the Windows Installer SDK from http://msdn.microsoft.com/platformsdk[^]).
If you need to install DirectX, you can bootstrap that as well, or include the redist executable as a custom action to be executed at a certain point in your installation. Again, VS.NET's Windows Installer project won't let you do this since it's UI is very limited. There are instructions for boostrapping this setup on the DirectX web site at http://msdn.microsoft.com/directx[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello
What is the replacement of DCOM in .Net ,how can we still write modules that communicate over a network and providing net transparency to develoers....as we used to do in DCOM
is webservices the answer?
or is there any better mechanism..
Thanks
Muhammad Ahmed
Ahmed
|
|
|
|
|
WebServices is a different base concept than DCOM was.
The closest replacement or equivalent is Remoting using a TCP channel.
You can also communicate over a TCP connection, call methods of a remote object and receive results.
What can't be done with remoting, however, is to instantiate a new object on a remote computer without a server program controlling this instantiation (whether the server object should behave like a singleton or create a new instance for every call, for example).
mav
|
|
|
|
|
can u refer any samples of this on codeproject technique...?
Ahmed
|
|
|
|
|
Just do a search for "Remoting" on CP or MSDN, you'll find plenty of references.
Regards,
mav
|
|
|
|
|
Hy everyone!
I do not know if my posting is really of topic, that's why it says "(OT?)".
I wonder if anyone of you could help me or if anyone of you knew where to look up for this:
We do want to send data between a Windows Application and a Java server which provides the webservice. The Java server is able to check the authorisation data (principal and credential) in an LDAP server. That's not the problem. Our problem is we do not know how to access the credentials via the JAVA server or the service respectively. This also involves we do not know for sure how to send the credentials from the Windows Application to the service/server.
What I did so far:
One remark to the first line: At the moment there isn't a correct string in there, because we do want to check if the server/the service in Java is able to get and read the data which I do send.
The string operations with ltemparray and so far are just to parse the local user account because it's "domaintype\useraccount" and the entries in LDAP are like this "useraccount@domaintype.domainname" so I haev to split the string and "invert" the order. So nothing magical in there. This works the way we wanted it to!
<br />
string domainname="ourdomainname";
string [] ltemparray=Regex.Split("","");<br />
Telephone[] lTelephone;<br />
AuthenticationData luserinfo = new AuthenticationData();<br />
WindowsIdentity lcuruser=WindowsIdentity.GetCurrent();<br />
ltemparray=Regex.Split(lcuruser.Name,@"\\");<br />
luserinfo.principal=ltemparray[1] + "@" + ltemparray[0] + "." + domainname;<br />
<br />
<br />
NameKeyService.EasyKeyService myproxy=new NameKeyService.EasyKeyService();<br />
<br />
CredentialCache lcredentialCache = new CredentialCache();<br />
<br />
NetworkCredential credentials=new NetworkCredential(luserinfo.principal,"password","domain");<br />
<br />
lcredentialCache.Add(new Uri(myproxy.Url),"Basic",credentials);<br />
<br />
myproxy.Credentials=lcredentialCache;<br />
<br />
lTelephone = myproxy.getCurrentTelephoneKeys(luserinfo);<br />
<br />
So I do send the credentials in the proxy class because I was not able to get the password from the local settings. That's why it is hardcoded at the moment.
If anyone of you knew how to fetch the password of the local account (which I was able to fetch) then please let me know, because as far as we found out we are not able to get it or not the way it is usable for our aim.
But back to my question, which might be a little of topic:
Which way does the Java service check or get the credentials? Or how will my colleague have to access the data in his class? Or how does a Java webservice (with JACs XML) store the credentials I sent?
Because he has to extract the credentials put them together with the principal and check the data with the LDAP to complete the Authentication.
So if anyone knew how to do this or where to look for please let me know.
And if anyone knew how to extract the credentials of the local account to store them in the AuthenticationData, then please let me know as well, because then it would be much easier for him to get along.
My solution (the part with the crendentials) is following what is described in the MSDN (Thread "Securing XML Web Services Created Using ASP.NET").
Thanks in advance for any solution or for any hint!
Stephan.
|
|
|
|
|
You can't get the Windows user password. What would be the point of security, then? You must either prompt for credentials (not uncommon; even Windows does this, though it uses DPAPI to store them for later use - don't consider rolling your own; and I'll tell you why in a second) or connect to a Web Service on the LAN (part of a Windows domain) using the default credential cache (see CredentialCache.DefaultCredentials , which includes the Windows identity for authentication like IE would when connecting on an intranet).
Besides, do not use BASIC authentication and send the domain passwords - of all passwords especially - in clear text to the unsecured web service! If you must use BASIC authentication, connect to a web service entirely over SSL (using https://, if available). Otherwise, a simple sniffer will pick up domain passwords and next thing you know you're fired, your companies bankrupt, and your sys admin executes you.
If you want articles on DPAPI and how to use it (though you probably won't need it if you use CredentialCache.DefaultCredentials ), read How To: Create a DPAPI Library[^].
You should also check out the Web Service Enhancements (WSE) 2.0 package from Microsoft at http://msdn.microsoft.com/webservices/building/wse[^]. This provides many, many options for industry-standard, SOAP-based (i.e., not tied to the wire protocol like HTTP authentication) authentication, encryption, digital signatures, and routing.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am trying to fetch the font information using following code
private void Form1_Load(object sender, System.EventArgs e)
{
IntPtr hdc = Win32API.GetDC(this.Handle);
try
{
LOGFONT lf = CreateLogFont("");
int ret = 0;
try
{
ret = Win32API.EnumFontFamiliesEx
(hdc, ref lf, new Win32API.EnumFontFamExProc(this.callback), 0, 0);
}
catch
{
System.Diagnostics.Trace.WriteLine("Excetion Happend!");
}
System.Diagnostics.Trace.WriteLine("EnumFontFamiliesEx = " + ret.ToString());
}
finally
{
Win32API.ReleaseDC(IntPtr.Zero, hdc);
}
}
private int cnt = 0;
private int callback(
ref ENUMLOGFONTEXDV lpelfe,
ref NEWTEXTMETRICEX lpntme,
uint FontType,
IntPtr lParam
)
{
try
{
++cnt;
string header = "no." + (cnt).ToString() + "::";
System.Diagnostics.Trace.WriteLine(header + lpelfe.elfEnumLogfontEx.elfLogFont.lfFaceName);
System.Diagnostics.Trace.WriteLine(header + lpelfe.elfEnumLogfontEx.elfLogFont.lfCharSet);
}
catch
{
System.Diagnostics.Trace.WriteLine("What happend?");
}
return cnt;
}
private const byte DEFAULT_CHARSET = 1;
private const byte SHIFTJIS_CHARSET = 128;
private const byte JOHAB_CHARSET = 130;
private const byte EASTEUROPE_CHARSET = 238;
private const byte DEFAULT_PITCH = 0;
private const byte FIXED_PITCH = 1;
private const byte VARIABLE_PITCH = 2;
private const byte FF_DONTCARE = (0 << 4);
private const byte FF_ROMAN = (1 << 4);
private const byte FF_SWISS = (2 << 4);
private const byte FF_MODERN = (3 << 4);
private const byte FF_SCRIPT = (4 << 4);
private const byte FF_DECORATIVE = (5 << 4);
public static LOGFONT CreateLogFont(string fontname)
{
LOGFONT lf = new LOGFONT();
lf.lfHeight = 0;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = 0;
lf.lfItalic = 0;
lf.lfUnderline = 0;
lf.lfStrikeOut = 0;
lf.lfCharSet = SHIFTJIS_CHARSET;
//lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = 0;
lf.lfClipPrecision = 0;
lf.lfQuality = 0;
lf.lfPitchAndFamily = (?_?) ;
lf.lfFaceName = "";
return lf;
}
it works well, but I am not able to toy with "lfPitchAndFamily", I want to fetch font names according to font family name and pitch.
Please guide
ps: what I found is InstalledFontCollection class in .NET Framework Developer's Guide does not give the list of all (installed) fonts . Please refer following link if you are interested
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/_gdiplus_enumerating_installed_fonts_usecsharp.asp
|
|
|
|
|
If you read about the LOGFONT structure in the Platform SDK (in the Windows GDI) section, it tells you that the first two low-order bits are the pitch and the 6 remaining high-order bits. You can define these as consts or enums (I like enums for consts, depending on what I'm doing since it organizes code a little better but still amounts to an actual constant value being compiled into IL):
public enum Pitch : byte
{
Default = 0x00,
Fixed = 0x01,
Variable = 0x02
}
public enum Family : byte
{
DontCare = 0x00,
Roman = 0x10,
Swiss = 0x20,
Modern = 0x30,
Script = 0x40,
Decorative = 0x50
} So, to use them assign lfPitchAndFamily to something like (byte)(Pitch.Variable | Family.Roman) . When this compiles, this will be 0x12 .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
(byte)(Pitch.Variable | Family.Roman) gives compile time error
((byte)Pitch.Variable | (byte)Family.Roman) works, but still it pics up all font names not only from the Roman family but also from all the families
|
|
|
|
|
Sorry 'bout that. Wasn't really thinking much about it.
If that's not working the way you expect it, I'd seriously take another look at the code surrounding EnumFontFamilies(Ex) . Be sure to read the docs in the Platform SDK if you haven't already.
Here's an example I threw together quick that works fine:
using System;
using System.Runtime.InteropServices;
class EnumFonts
{
static void Main(string[] args)
{
string family = null;
if (args.Length > 0) family = args[0];
IntPtr hdc = GetDC(IntPtr.Zero);
try
{
EnumFontFamilies(hdc, family,
new EnumFontFamProc(Callback), IntPtr.Zero);
}
catch (Exception ex)
{
Console.Error.WriteLine("There was an error enumerating the " +
"font families: " + ex.Message);
}
finally
{
ReleaseDC(IntPtr.Zero, hdc);
}
}
static IntPtr Callback(ref ENUMLOGFONT font, ref NEWTEXTMETRIC metric,
int fontType, IntPtr lParam)
{
Console.WriteLine(font.FullName);
return new IntPtr(1);
}
[DllImport("user32.dll")]
static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll")]
static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("gdi32.dll", CharSet=CharSet.Auto)]
static extern IntPtr EnumFontFamilies(
IntPtr hdc,
string family,
EnumFontFamProc proc,
IntPtr lParam);
delegate IntPtr EnumFontFamProc(
ref ENUMLOGFONT font,
ref NEWTEXTMETRIC metric,
[MarshalAs(UnmanagedType.U4)] int fontType,
IntPtr lParam);
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
struct LOGFONT
{
public int Height;
public int Width;
public int Escapement;
public int Orientation;
public int Weight;
public byte Italic;
public byte Underline;
public byte StrikeOut;
public byte CharSet;
public byte OutPrecision;
public byte ClipPrecision;
public byte Quality;
public byte PitchAndFamily;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
public string FaceName;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
struct ENUMLOGFONT
{
public LOGFONT LogFont;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)]
public string FullName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
public string Style;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
struct NEWTEXTMETRIC
{
public int Height;
public int Ascent;
public int Descent;
public int InternalLeading;
public int ExternalLeading;
public int AveCharWidth;
public int MaxCharWidth;
public int Weight;
public int Overhang;
public int DigitizedAspectX;
public int DigitizedAspectY;
public char FirstChar;
public char Lastchar;
public char DefaultChar;
public char BreakChar;
public byte Italic;
public byte Underlined;
public byte StruckOut;
public byte PitchAndFamily;
public byte CharSet;
[MarshalAs(UnmanagedType.U4)] public int Flags;
[MarshalAs(UnmanagedType.SysUInt)] public IntPtr SizeEM;
[MarshalAs(UnmanagedType.SysUInt)] public IntPtr CellHeight;
[MarshalAs(UnmanagedType.SysUInt)] public IntPtr AvgWidth;
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the reply.
I checked the code on my machine, unforutnately it fails to fetch all fonts.
According to MSDN documentation use of the EnumFontFamiliesEx function is recommended.
in my code only the lfPitchAndFont part is not working, but it collects all fonts from all families.
if you wish i can send that snippet.
regards
|
|
|
|
|