|
I wish for my c# program to search, through a list of Addresses, for particular Address. The user will enter a couple of letters in a textbox and then the program will go out and search a Sql database for that Address.Can some on give me some ideas on how to do this or maybe some samples ?
Thanks in advance..
|
|
|
|
|
Hi,
sql supports wildcard search by using the word 'like'. Have a look at http://www.sql-tutorial.net/SQL-LIKE.asp[^].
All you have to do is build a GUI (ASP.NET or Windows Forms) and connect your database with the GUI.
Regards
Sebastian
|
|
|
|
|
You asked this before almost a week ago, you recieved all the help to get this done. Which part are you stuck on now? You *know* the SQL wildcard char is %, you said you understood that. Where is the problem??
If in postal code textbox (we will call it txtPostalCode) they enter 92 then you do
SQL= "select * from db.table where postal_code like %" & ToInt32(txtPostalCode.Text) & "%";
That will catch all results with *92*; it would catch 92010 or 08920 etc
Should be sufficient to complete your project.
ToInt32 will catch common exceptions....
modified on Thursday, January 15, 2009 8:58 AM
|
|
|
|
|
Is the a specific reason you 1 voted me for helping you *again*...
prick.
modified on Thursday, January 15, 2009 9:20 AM
|
|
|
|
|
Balanced
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
It's extremely upsetting. He posted the same question here,[^] received the same help he is going to get here. In fact I took it one step further and mapped out his SQL statement (without fear of SQL injection, clearly it is a homework project) and he has the balls to be so ungrateful. Sometimes it's discouraging, you know?
Edit: Thanks, it's not so much I care about it, just the fact that it's done for no reason, when he actually * received* help.
|
|
|
|
|
Yeah - that's why I balanced his vote.
Just rise above it! There are far too many of these types on the interweb to let them get to you. Just take pleasure in helping those that deserve and appreciate your assistance.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Why did you reply to yourself? He won't receive the message, and I doubt he's a regular on the boards. The ungrateful little oik will have had an email with your answer, and that'll be it until he needs help finding his backside again.
|
|
|
|
|
Hi All,
I have COM component which is referred in my C# application. Visual studio has generated interop for the COM and able to call the methods from C# code.
This component has a method with parameters being optional. Now I am not able to force the compiler to use default values of these optional parameter instead of explicitly passing them. In other words I don’t want to pass any values to call this method. I tried using System.Reflection.Missing.Value. but it throw error saying type missmatch. Method is looking for integer type value.
Is there any I can call this method without passing any parameters and creating a wraper to this assembly.
Thank you,
Krishnaraj Barvathaya B
|
|
|
|
|
Optional parameters don't exist in C# unfortunately. The best you can do is create an overload and have the overload call the full method.
I hate to say it, but you can do this in VB! There was talk of it being introduced into C#4 but I don't know if it's made it or not.
void Method(int a)
{
Method(a, 0);
}
void Method(int a, int b)
{
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I'm pretty sure optional parameters made it in. There's an inititive to introduce new features to both C# and VB.NET at the same time. This also means syncronizing the existing feature sets between the two languages where appropriate. For example, C# gets the optional parameters VB.NET supports, but VB.NET does NOT get the unsafe code and pointer support that C# has. At least, not yet...
|
|
|
|
|
Optional parameters did make it in to the underlying IL but they aren't exposed in C# yet (C# 4.0 will support them). There is an effort to keep the two languages more in-sync with one another but it isn't across the board with all language features, as you mentioned. Another exmaple is that C# will not get the "XML literal" syntax VB supports.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Thank you every one for your answers.
From your answers I am able to conclude that there is no straight forward way to call a method with optional parameter by forcing to use its default value. So I created a wrapper class in VB.net with number of overloaded methods to match its optional implementation. Looks to be working fine.
Krishnaraj Barvathaya B
|
|
|
|
|
For the parameters you're not interested in, just pass either:
System.Type.Missing
System.Reflection.Missing.Value
(either will work)
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
VB & C# to Java Converter
Java to VB & C# Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB, C#, or Java to C++
|
|
|
|
|
This will work only in case the expected parameter is of reference type such as string. It doesn’t work if the method is looking for Integer type or any other primitive types. If you pass either System.Reflection.Missing. System.Type.Missing or System.Reflection.Missing.Value compiler shows up error saying type mismatch. So after lot of search, I think there is only way to break this barrier is by creating a wrapper class in VB.net and referencing the same.
Krishnaraj Barvathaya B
|
|
|
|
|
Hi i have code on 64 bit system on windows 2008 server enterprise.
i want to read some value of my application in it through C# code, when i read by default it reads from wow6432 node only, but i need to read value from 32 bit node.
64 bit key value
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\COMPANY\product Name\1.0\folder
32 bit key value
HKEY_LOCAL_MACHINE\SOFTWARE\COMPANY\product name\1.0\folder
how write code to force reading value from folder32 in 32 bit registry hive?
i have set the flag for 32 bit system read that is:
UIntPtr HKEY_LOCAL_MACHINE = (UIntPtr)0x80000002;
const int KEY_WOW64_32KEY = 0x0200;
const int KEY_QUERY_VALUE = 0x1;
but still when i give like
RegistryHelper regHelper = RegistryHelper();
regHelper.BaseRegistryKey = Registry.LocalMachine;
regHelper.SubKey=@"HKEY_LOCAL_MACHINE\SOFTWARE\COMPANY\product name\1.0\folder"
string sPath = regHelper.ReadString("Path");
it gives sPath=null only.
it is searching in 64 bit node only. please help me resolve this issue.
thanks in Advance.
Hemal Kotak
|
|
|
|
|
You are misunderstanding what WOW64 means.
WOW64 (windows on windows 64) is a windows 32bit emulator that runs on windows 64 bit. The wow64 folders/regs keys are for data from 32bit programs that are running on windows 64 (via the emulator).
You obviously are writing a 32bit program. Hence, it is running on WOW64. Which means when you write to the registry it goes in the WOW64 location. This is the correct behaviour. On windows 64, the registry is 64bit, and cannot be accessed by 32 bit programs. WOW64 allows a special area of the registry to be accessed by 32 bit programs.
(By the way, by default c# compiles in "architecture agnostic mode" which means it is both a native 32 and 64 bit program at the same time. If you are using C# you have obviously changed the settings to be for a 32bit cpu only. Consider changing it back. Right click on the project, go to properties, and look at the build tab. There is an option called "platform target" this should be set to "any cpu". If you do this, on a win64 system, the app will run as a native 64 bit app, so won't be using wow64 any more. I suspect you have it set to x86 which means 32bit cpus)
Simon
|
|
|
|
|
Thanks Simon I will do that.
-Hemal
Hemal Kotak
|
|
|
|
|
My app needs to take a pdf file and compress it into an .arc file (for a third party bit of software to pick up, so i have no choice in the compression format).
I have googled it but am struggling to find any c# solutions or opensource api's.
Any links, ideas etc most welcome
Mark
|
|
|
|
|
|
Good day. I'm writing an application where I specify types in a config file and these types then need to be instantiated through reflection.
How can I create a System.String object through reflection? And a System.Int32 object with a value other than 0?
I've got the following code:
Type paramType = Type.GetType("System.String");
object obj = Activator.CreateInstance(paramType);
but when I try to do this for a System.String, it tells me that such a constructor doesn't exist (one with no parameters). When I run the code for a System.Int32 object, then the object is created, but I cannot pass the constructor a default value such as Activator.CreateInstance(typeof(int), 3, 5);
How can I create a type such as System.String, System.Int32 or such a type and assign a value when it's created, using reflection?
|
|
|
|
|
Hi,
i'm not sure why you are using the Activator-object. The string has no constructor without parameters (check http://msdn.microsoft.com/en-us/library/system.string.string.aspx[^]), so you have to pass something to get a string object. What you could try is to use the ConstructorInfo of the Type.
<br />
ConstructorInfo oInfo = paramType.GetConstructor(new Type[] { typeof(char*) });<br />
object oString = oInfo.Invoke(new object[] { "This is a test."} );<br />
Hope this helps you a bit.
Regards
Sebastian
|
|
|
|
|
The values in my app.config file actually looks like this.
<parameter type="System.String" value="32">
<parameter type="System.Int32" value="32">
Now, I can't call
int i = new int("32") or,
string myString = new string("32"),
since no such constructors exist. I need to somehow create objects of these types and assign these values to them. But I'm looking at a generic way of doing this.
(I don't want to write code like
object obj = null;
if(paramType is Int32)
obj = 32;
else if(paramType is String)
obj = "32";
I want to avoid code like this.
Any ideas?
|
|
|
|
|
Take a look at the TypeConverter class.
object obj = TypeDescriptor.GetConverter(paramType).ConvertFromInvariantString("32");
|
|
|
|
|
This one's the answer I was looking for. Thanks a lot for the help.
|
|
|
|