|
Oh, the keydown event does fire for the DELETE key. Thanks!
|
|
|
|
|
Dear Friends
I am developing my first program in C# when I have created the database connectivity in C# as below
SqlConnection mysqlconnection = new SqlConnection("server=murtuza; Trusted_connection=Yes;database=northwind");
OleDbConnection myconn = new OleDbConnection (@"Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=company;data source=murtuza;initial catalog=northwind;integrated security=SSPI;workstation id=ACER-157FBA01C8;packet size=4096");
OleDbCommand mycmmd= new OleDbCommand (myselect, myconn);
myconn.Open();
OleDbDataReader myreader;
myreader= mycmmd.ExecuteReader();
when i reach the myreader= mycmmd.ExecuteReader(); this statment i am getting error please can u tell me the simple way to connect to a sql server database
|
|
|
|
|
I'm confused by the use of SqlConnection in your first code example and OleDbConnection in your second.
And what is the error? Is it a connection error, or an error with your select statement?
Put a try-catch block around the ExecuteReader and inspect the Exception.Message property.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
I'm not only confused by your usage of two connections but I'm also unclear what the error could be. Especially with client/server systems there could be any number of errors that are legitamate and at multiple locations. Please provide more information.
|
|
|
|
|
I am working with a fixed length file that I will be parsing at run time and inserting into a SQL table. I would like to store the insert statements in a table. The problem with this is that the file contains some EBCDIC characters that need to be converted to ASCII before inserting into the database. There are also other functions that need to be carried out on other fields before the data is pushed into the database tables. I don't want to hard code the insert statements as the file layout could change and it would be easier to change the insert statements than it would be to change and redistribute the program. Is there a way to evaluate the functions in the insert statements at run time?
|
|
|
|
|
JMichael2468 wrote:
There are also other functions that need to be carried out on other fields before the data is pushed into the database tables.
Do you mean, functions that have been coded in C# that you want to call, or SQL functions?
If the former, you can use reflection. If the latter, well, I don't know.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
I want to Upload a file.
Here is my code..
Page 1:
WebClient client = new WebClient();
client.UploadFile( "http://ft-rt-005/test/upload1.aspx","POST","G:\\Water lilies.jpg");
Page 2:
foreach(string f in Request.Files.AllKeys)
{
HttpPostedFile file = Request.Files[f];
file.SaveAs(Server.MapPath(".\\upload\\"+ file.FileName));
}
I am uploading a file to Page 2 using client.UploadFile().From Page 2 ,i am saving to the server.But whenever client.UploadFile() is invoked,my application searches the file in server.It is not searching in the client machine.
I want to upload from the client machine.Can anybody help me..
Thanks
Ramesh
|
|
|
|
|
i use this code to set the text of a second form from within another:
public string labelTitoloText
{
set
{
this.labelTitolo.Text = value;
}
}
but i get a compiler error until i use the keyword "static":
public static string labelTitoloText
{
set
{
this.labelTitolo.Text = value;
}
}
why?
|
|
|
|
|
static implies that the member method or field does not belong to any object but to the type itself but is available to all objects due to it. In short, there is no concept of "this " for something tagged static .
|
|
|
|
|
If you declare something static it means that you don't (as a matter of fact you can't) instantiate it before you use it. One of my favorite examples of the use of static is say you are writting a class that keeps track of how many instances of that particular object exists. Inside that class you declare a static variable that will have an initial value of zero. In the constructor of your object you increment that static variable by one and in the destructor you decrement that static variable by one to reflect the creation/destruction of your objects. Now, since it's a static variable you can't increment using the "this" keyword since that will refer to an instance variable. You need to use a the actual class name and then static variable to increment it to be like: MyClass.instance++ or MyClass.instance-- And since its a static variable that all of your classes "share" you could query that static variable from any of your instantiated objects because they will all have the same value.
Here's MSDN explanation of the keyword static: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfstaticpg.asp
|
|
|
|
|
|
Hi
my program updates only farm name I want to search through loop farm name and it should
update address,
user and password from the existing file name
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("c:/farm-config.xml");
XmlNode farm=xmldoc.SelectSingleNode("/root/farm-config/farm/@name");
MessageBox.Show(farm.InnerText);
farm.InnerText="devxcv1";
MessageBox.Show(farm.InnerXml);
xmldoc.Save("c:/farm-config.xml");
My XMl strucutrue is as given below
<?xml version="1.0" encoding="UTF-8"?>
<root>
<farm-config>
<farm name="sanjay">
<connection address="127.0.0.1" user="dog" password="cat">
<lastjob>Copy-All</lastjob>
<lastconnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
</connection>
</farm>
<farm name="ram">
<connection address="localhost" user="root" selectedConnection="1" password="daask">
<lastJob>Copy-All</lastJob>
<lastConnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
</connection>
</farm>
</farm-config>
</root>
--- supoose i want to find thr loop ram and i want o change address,user and password attribues value thr loop
if i change it changes the upper ones farm name=sanjay 's address,user and password
regards
sanjeev
|
|
|
|
|
Hi!
I have a class that looks like this:
using System;
using System.Collections;
namespace AreaData
{
[Serializable()]
public class Wrapper
{
ArrayList _Data = new ArrayList();
int _MovieLength = 0;
public Wrapper()
{
}
public Wrapper(ArrayList a, int l)
{
_Data = a;
_MovieLength = l;
}
public ArrayList Data
{
get{return _Data;}
}
public int MovieLength
{
get{return _MovieLength;}
set{_MovieLength = value;}
}
}
}
In my mainform I have a datagrid which is bound to the ArrayList of this class. Everything works fine, except when I try to change a value in the datagrid at runtime, then at first the change doesnt commit, and after that when I click somewhere else I get an error box:
"Error when committing the row to the original data store"
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index. Do you want to correct the value?
Everyting works fine, when the arraylist is located in the same class as the datagrid!
Any solution to this would be really appreciated!
thanks
/Rickard
|
|
|
|
|
//how to override WndProc()
Form aForm = new Form()
// after this call, aFrom's WndProc() method are replaced by a another func
aForm.foo();
public foo()
{
// code to override WndProc
}
Can anyone help?
|
|
|
|
|
You mean, like:
class MyForm : Form
{
protected override void WndProc(ref Message m)
{
}
}
The virtual method is defined in Control, which Form derives from.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Hi Marc,
the way you just pointed out is the conventional one.
What I want is dynamicly override the control's method.
|
|
|
|
|
How much more dynamic can you get than what Marc has shown you? Overriding WinProc gives the object the chance to inspect the message and determin what to do including pass it along.
|
|
|
|
|
Ok, suppose I am writting a dll in C#, the dll will send to current window
some message. My customs who will use that dll have to define override WndProc method. So I am thinking of create a function so that customs dont need to explicitly write their WndProc.
|
|
|
|
|
jinzhecheng wrote:
My customs who will use that dll have to define override WndProc method.
Then use an event handler that they can attach to, and if they handle WndProc themselves, you don't. Something like this:
class MyForm : Form
{
public delegate bool WndProcOverrideDlgt(ref Message m);
public event WndProcOverrideDlgt WndProcOverride;
protected override void WndProc(ref Message m)
{
bool handled=false;
if (WndProcOverride != null)
{
handled=WndProcOverride(m);
}
if (!handled)
{
}
}
}
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Marc, AFAIK, delegates declared as events cannot have a return type except void. This is because more than one client could have subscribed to the event, so there is no way to figure out which of those clients' return values should get back.
I think the best way is to pass another object with WndProcOverride that encapsulates a bool variable and has logic to ensure that once one client has handled, it is set to true etc..
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi Marc,
your solution is cool, however , you see, you still defined an override version of WndProc INSIDE myForm class,
What I want is like this:
Form a = new Form();
// after this call, the WndProc is overrided!!
overrideWndProc(a);
it looks like crazy, I am now wondering if its possible, maybe I should use
a proxy, that can seize message before the form get it
|
|
|
|
|
A delegate is a lot simpler than a proxy.
And delegates/events can have a return type, it's just not standard.
So yes, the real way to do it is to define your own specialized EventArgs class that has the "handled" flag.
But yes, if you want something that can hook a form that doesn't implement WndProc and gives you a way to hook it, then you have to do something like this:
PreFilter preFilter=new PreFilter();
Application.AddMessageFilter(preFilter);
...
class PreFilter : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
}
}
That may be more what you're looking for. You can then test if the message's HWnd is the same as the Form's hWnd that you want to hook, using:
form.Handle
which should be the same thing as the HWnd value.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Marc ,
Finaly got it .
Yeah , I think a message filter is the best solution.
Thanks!
here is a summary:
1st step:
// create a filter
public class MsgHandler : System.Windows.Forms.IMessageFilter
{public bool PreFilterMessage(ref msg){// do it here}}
2nd step:
//create a method
public void OverrideWndProc(){MsgHandler msgHandler =new MessageHandler();
Application.AddMessageFilter(msgFilter);}
3rd step:
user call this func before App run.
Thats it!
|
|
|
|
|
But Marc is raising an event there...
class MyForm : Form
{
public delegate bool WndProcOverrideDlgt(ref Message m);
public event WndProcOverrideDlgt WndProcOverride;
protected override void WndProc(ref Message m)
{
bool handled=false;
if (WndProcOverride != null)
{
handled=WndProcOverride(m);
}
if (!handled)
{
}
}
}
So
Form a = new MyForm();
a.WndProcOverride += new WndProcOverrideDlgt(WndProc_Handler);
...
bool WndProc_Handler(ref Message m)
{
}
p.s If S. Senthil Kumar is right and you can't have bool delegate (I dunno and lazy to look up) you can do it like public delegate void WndProcOverrideDlgt(ref Message m, ref bool handled);
At least I hope so
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
Hi
I want to delete the particular node from xml file
Supoose i want to delete farm name="ram" it should delete all the contents of element farm
Program should search from the file for particular node and delete
I have written the code for deleting but it deletes from UPPer node only it deletes ram what ever you give the farm name dev2.
my code is given below pls modify it
private void button15_Click(object sender, System.EventArgs e)
{
strtxt_BD_farmName="dev1";
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("c:/farm-config.xml");
XmlNodeList farm=xmldoc.SelectNodes("//farm");
foreach(XmlNode n in farm)
{
if (n.Attributes.GetNamedItem("name").Value == strtxt_BD_farmName)
{
MessageBox.Show("Enter Farm name found");
XmlNode xNode;
XmlElement xElmntFamily;
// Search for a particular node
xNode = xmldoc.SelectSingleNode("//farm-config");
if (!(xNode == null))
{
xElmntFamily = (XmlElement) (xNode);
xElmntFamily.RemoveChild(xElmntFamily.SelectSingleNode("farm"));
FileStream fsxml = new FileStream("c:/farm-config.xml",FileMode.Truncate,FileAccess.Write,FileShare.ReadWrite);
xmldoc.Save(fsxml);
fsxml.Close();
//xNode=null;
farm=null;
//xmldoc.Save("c:/farm-config.xml");
MessageBox.Show(strtxt_BD_farmName + " deleted");
}
}
}
This is my original XMl structure
<?xml version="1.0" encoding="UTF-8"?>
<root>
<farm-config>
<farm name="ram">
<connection address="localhost" user="ram" password="ram">
<lastjob>Copy-All</lastjob>
<lastconnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
<database start="0" name="bd_plc1_house1_14022005" sourceType="amacs">
<tables state="0" name="feed_delivery">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
</database>
</connection>
</farm>
<farm name="dev2">
<connection address="localhost1" user="root1" selectedConnection="1" password="daask2">
<lastJob>Copy-All</lastJob>
<lastConnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
</connection>
<database state="0" name="bd_plc1_house1_14022005" sourceType="amacs">
<tables state="0" name="feed_delivery">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="PRODDAY" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
<tables state="0" name="production_actualbirds">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="PRODDAY" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
</database>
</farm>
</farm-config>
</root>
after deletetion my xml structure will look like in the given format but according to my program it is deleteing
farm name=ram as i should delete farm name=dev2 pls someone give me code for that
<?xml version="1.0" encoding="UTF-8"?>
<root>
<farm-config>
<farm name="dev2">
<connection address="localhost1" user="root1" selectedConnection="1" password="daask2">
<lastJob>Copy-All</lastJob>
<lastConnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
</connection>
<database state="0" name="bd_plc1_house1_14022005" sourceType="amacs">
<tables state="0" name="feed_delivery">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="PRODDAY" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
<tables state="0" name="production_actualbirds">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="PRODDAY" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
</database>
</farm>
</farm-config>
</root>
Warm regards,
sanjeev
|
|
|
|