|
you could do it like this or by using a sql/odbc/oledb datadapter (e.g. system.data.oledb.oledbdataadapter) and set it up. this is a bit more complicated and i used it only once so you should go and google for it. the msdn has some nice explaination about how to use this thing. if you want to do it by yourself, you will have to have an array (or list or anything else) containg the values and the fieldname (a 2-dimensional array would do the job
if you got a table consisting of 3 columns (e.g. id, name, postdate) you would need an array like this:
data[0,0] = "id";<br />
data[0,1] = 0;<br />
data[1,0] = "name";<br />
data[1,1] = "myname";<br />
data[2,0] = "postdate";<br />
data[2,1] = "2006-05-02";<br /> (alternatively you could use 2 single array, one holding the column names and the other one holding the column values)
it would be easy to generate the statement then - it could look like
string sqlquery = "INSERT INTO tablename (";<br />
string comma = "";<br />
<br />
for (int i = 0; i < data.GetLength(0)-1; i++)<br />
{<br />
if (i > 0)<br />
comma = ","<br />
sqlquery = sqlquery + comma + data[i,0];<br />
}<br />
<br />
sqlquery = sqlquery + ") VALUES (";<br />
<br />
for (int i = 0; i < data.GetLength(0)-1; i++)<br />
{<br />
if (i > 0)<br />
comma = ","<br />
sqlquery = sqlquery + comma + "'" + data[i,1] + "'";<br />
}<br />
<br />
sqlquery = sqlquery + ");";<br />
this code would produce a query like
<br />
INSERT INTO tablename (id,name,postdate) VALUES ('0','myname','2006-05-02');<br />
since this can be a lot of work you should make yourself familiar with the dataadapters
|
|
|
|
|
Thanks many!
|
|
|
|
|
yeah and maybe take a look at concurrencymanager.
Tom Wright
tawright915@gmail.com
|
|
|
|
|
Hello everybody,
i've been searching the forums for a similar question but wasn't successfull yet.
So i decided to ask the question by myself.
Is there ANY possibility to create a pointer in a generic class, which points to a variable of one of the specified typeparameters.
A little example
<br />
class myclass <T><br />
{<br />
unsafe T * myptr = null;<br />
}<br />
The compiler tells me he isn't able to declare a pointer of a "managed type" (I hope this is the correct translation so let me know if that doesn't make any sense)
Is there a workaround to make this pointer point to the specified address AND act like a "native" pointer (please don't tell me about a void pointer - it just doesnt work for my purposes)
____________________________________
If this should not be possible (yeah, i almost gave up ) is there a solution for my problem anyways? It's about associating some variable with another one.
<br />
public class dbTable<br />
{<br />
ulong myvar = 0;<br />
dbColumn<ulong> mycol = null;<br />
<br />
public dbTable()<br />
{<br />
mycol = new dbColumn<ulong>();<br />
mycol.MapVariable(ref myvar);<br />
}<br />
}<br />
<br />
public class dbColumn<T><br />
{<br />
public T mysecondvar;<br />
public MapVariable(ref T VarToMap)<br />
{<br />
mysecondvar = VarToMap;<br />
}<br />
}<br />
That example doesn't work of course because it will try to assign the value of "VarToMap" to "mysecondvar". When trying to retrieve "VarToMap"-address and assign it to "mysecondvar" the compiler throws out some errors too (the address wasn't meant to be the value of a ulong variable).
I want to be able to get the following output when performing this code:
<br />
dbTable mytable = new dbTable();<br />
mytable.myvar = 5;<br />
<br />
Console.WriteLine(mytable.myvar.ToString());<br />
Console.WriteLine(mytable.mycol.mysecondvar.ToString());<br />
<br />
mytable.mycol.mysecondvar = 3;<br />
<br />
Console.WriteLine(mytable.myvar.ToString());<br />
Console.WriteLine(mytable.mycol.mysecondvar.ToString());<br />
This should produce:
<br />
5<br />
5<br />
3<br />
3<br />
So i want one Variable to keep the Value and another one to point at it BUT i need to be able to specify the type of both variables (void pointer would do the job but i'm not able to retrieve or assing values to the variable its pointing to because the "=" operator wasn't defined for!)
I hope that someone has a solution for this problem (as already mentioned, i don't care about how it is realized as long as the requirements above are met)
I would like to hear any kind of comment because i'm really desperated.
If this i a bas idea at all it would be nice if you could tell me why i shouldn't do it like this...
Thanks in advance
mik
-- modified at 9:42 Wednesday 30th August, 2006
|
|
|
|
|
Dear All,
I am creating a Image Library and want to know what can the best and standard procedure to do this.
Concept is to have all the images needed by all projects (dlls and exes) in the product at a central place (in a single DLL) making it easy to distribute and maintain.
There are 2 ways of doing this.
1) Creating a new project, add all the images to it using "Add Existing Item" and set Build Action=Embeded Resource for each image.
OR
2) Creating a new project>Add new Item>Resources File and then adding all the images to it and setting Build Action=Embeded Resource for each image. Doing this will provide me a strongly typed DLL which will provide a property like access to all images. But .resx are mainly for localization. And here I am not localizing images.
My question is what is the standard way of doing this?
Do you guys know pros or cons of any of these methods?
Is anybody there knowing how Microsoft do it??? (When they need to create an image library)
Any links or articles for this?
Most important is, will the second (2) way will have any negative effect on start up time?
Regards,
----------------------------------------------------------------------------------
Jayvardhan Patil.
|
|
|
|
|
I have an application whose shortcut is placed on the desktop. Now whenever i double-click that icon, I want to get the information for that icon like Icon name, Icon target path, Icon working directory. The reason behind this is from one of the functionality the working directory changes for the application. So through Windows API or in C#/C++ I want to change the working directory for the icon which is double-clicked.
Plz guide me soon and at the earliest, if possible.
Regards.
Chilly
|
|
|
|
|
System.Drawing.Icon.ExtractAssociatedIcon(String) might be helpful. Peeking inside it with Reflector should be even more halpful.
|
|
|
|
|
Dear users,
I have the following XML:
<name>MyName</name>
<descr>MyDesc</descr>
So the serialisation in C# would be:
[XmlElement("name")]
public string Name
{
get { return name; }
set { name = value; }
}
[XmlElement("descr")]
public string Descr
{
get { return descr; }
set { descr = value; }
}
But what if I have this?
<name>MyName</name>
<descr pos="after" type="string">MyDesc</descr>
Is the above possible to be serialised?
Thank you very much.
Regards,
Steven
-- modified at 5:52 Wednesday 30th August, 2006
|
|
|
|
|
hi,
have a look at System.Xml.Serialization namespace. You'll find what you need there
Do your best to be the best
|
|
|
|
|
Thanks karkster.
I have looked actually. However, the best I could find is how to serialise this:
<descr pos="after" type="string" val="MyDesc" />
which is not what I want like this:
<descr pos="after" type="string">MyDesc</descr>
|
|
|
|
|
is it possible to add a folder in a tree view, if i drag and drop a folder from my desktop or local drives to my application tree view control.
Plz help me... if it is possible? how i have to proceed....
thanks in advance.........
|
|
|
|
|
Hi ,
Am new to Graphics and Imaging.
i tried to draw a *.jpg image[which is a MRI image of human brain] using SetPixel(..).
But while executing its throwing exception as "SetPixel is not supported for images with indexed pixel formats".
What does it actually mean and how can i resolve it?
Thanks
|
|
|
|
|
Hi,
Vsree wrote: i tried to draw a *.jpg image
what do you mean by drawing a jpg image? Do you want to draw pixel by pixel in your application and save as a jpg or do you want to display a jpg?
Do your best to be the best
|
|
|
|
|
Actually i tried to load an JPEG image from file and set its pixel color to a new value and redraw it using Graphics object and save it in the file.
<br />
Color c;<br />
for ( int x=0; x<imgDefault.Width-1; x++ )<br />
{<br />
for ( int y=0; y<imgDefault.Height-1; y++ )<br />
{<br />
c = imgDefault.GetPixel( x, y );<br />
c = Color.FromArgb( c.ToArgb() + 100 );<br />
imgDefault.SetPixel( x, y, c );<br />
}<br />
}<br />
pe.Graphics.DrawImage( imgDefault, 0, 0 );<br />
I loaded a MRI Scan image of human brain and tried to do the above work,
which threw error as:"SetPixel is not supported by Indexed pixel format"
What does it mean?
Please help me
|
|
|
|
|
SetPixel doesn't work with images with indexed pixel format. Try copying your image to a new bitmap pixel by pixel and make your changes on that bitmap
Do your best to be the best
|
|
|
|
|
Try this:
Image imgDefault;
Bitmap imgSaveForSetPixel = new Bitmap(imgDefault.Width, imgDefault.Height);
using (Graphics g = Graphics.FromImage(imgSaveForSetPixel)) {
g.DrawImageUnscaled(imgDefault, 0, 0);
}
Robert
|
|
|
|
|
hey guys, having a little trouble here...
what im trying to do is set focus to an Edit field on a different application... so im doing this, to test im using Spy++ to get the handle to a random field on a random application,
Handle: 2692780
SendMessage(hWnd, WM_SETFOCUS, IntPtr.Zero, null);
it doesnt seem to be working
ideally what i want is to bring focus to the entire process, and focus the control...
am i on the right track here?
|
|
|
|
|
Hi!
The documentation for WM_SETFOCUS states that this is a notification that's being sent to a window when it's receiving the focus, it doesn't actively set the focus!
How about using SetFocus()[^]?
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Hello Friends,
I want to make AGC i.e. Automatic Gain Control OFF or ON through coding.
I have seen "KSPROPERTY_AUDIO_AGC" in the platform SDK but can't understand
how to use it.
Thanks in Advance.
Rahul Kulkarni
|
|
|
|
|
when i declared a method string getName(){return this.name}; string getAddress(){return this.address;}... get appears like blue color its means c# word, then this methods get and set how can i use them or how its use
i hope, i can explain good
Dios creo un equipo perfecto a los demas los lleno de extranjeros
|
|
|
|
|
You should use properties for this, e.g.,
public string Address
{
get
{
return this.address;
}
set
{
this.address = value;
}
}
Or, just for get.
public string Address
{
get
{
return this.address;
}
}
Kevin
|
|
|
|
|
Hello Legolas,
Actually set & get both are keyword of C#.
You can use it when you define any property for class like...
class TimePeriod
{
private double seconds;
public double Hours
{
get { return seconds / 3600; }
set { seconds = value * 3600; }
}
}
You can get more help from here.
regards,
Divyang Mithaiwala
System Engineer & Software Developer
|
|
|
|
|
If you want to use get & set you have to use a Property. (Unless you are programming in Java which don't have get & set)
It seems like you have two options.
1. To have TWO methods FOR EACH property, of get and set, eg. string getName() { return this.name; } void setName(string NewName) { this.name = NewName; }
(Just like in Java)
2. You can use it as a Property (the easyer and more comfort one), eg.:
string Name
{
get { return this.name; }
set { this.name = value; }
}
and to use it in code:
string thisname = obj1.Name;
obj1.Name = "My New Name";
(You don't use the "()" in a Property)
You can learn a little bit more if you read a little about this chapter.
Hope I helped.
NaNg.
|
|
|
|
|
using System;
class Circle
{
public int X
{
get
{
return(x);
}
set
{
x = value;
// draw the object here.
}
}
int x;
}
class Test
{
public static void Main()
{
Circle c = new Circle();
c.X = 35;
}
}
In this code, the get or set accessor is called when the property X is referenced.
Vikas Amin
EATON
PUNE
|
|
|
|
|
But whatis better using get & set or using getName();??
Dios creo un equipo perfecto a los demas los lleno de extranjeros
|
|
|
|