|
Additional to what Andrei submitted, you could check the return value from your stored procedure to see if the record exists. For example in your SP you could use:
IF EXISTS(Select Pinfo from
Where Pinfo = @info)Begin
RETURN 2
END
Else
BEGIN
<insert stuff="" here.......="">
END
If the return value is 2 then you know the record exists. Check out SQLParameters and ParameterDirection.ReturnValue for help.
HTH
F
|
|
|
|
|
Hi there, I am currently in negotiations with a customer that wishes to purchase an application that I have developed for him in C#. My dilemma is that although I trust him I wish to be able to give him a working copy of the application knowing that he will not just be able to 'steal' it. Seeing as the application needs to be online to function in any case I thought that maybe I could incorporate a request into the application to verify whether or not it should run so that I can disable it if something smells funny rendering the application useless.
I have attempted to use a HttpWebRequest request to try and retrieve the string of a file on my website and authenticate it that way but it seems that it caches somewhere or something but it takes a very long time for it to take effect. Here is my current Verification method:
private bool allowedToRun()<br />
{<br />
StringBuilder sb = new StringBuilder();<br />
<br />
byte[] buf = new byte[8192];<br />
<br />
HttpWebRequest request = (HttpWebRequest)<br />
WebRequest.Create("urlOfMyWebPage.html");<br />
<br />
HttpWebResponse response = (HttpWebResponse)<br />
request.GetResponse();<br />
<br />
Stream resStream = response.GetResponseStream();<br />
<br />
string tempString = null;<br />
int count = 0;<br />
<br />
do<br />
{<br />
count = resStream.Read(buf, 0, buf.Length);<br />
<br />
if (count != 0)<br />
{<br />
tempString = Encoding.ASCII.GetString(buf, 0, count);<br />
<br />
sb.Append(tempString);<br />
}<br />
}<br />
while (count > 0);
<br />
MessageBox.Show("Allowed to run: " + sb.ToString());<br />
return Convert.ToBoolean(sb.ToString());<br />
<br />
}
Ideas?
|
|
|
|
|
Have you thinked to use a webservice?
Visit my blog at http://dotnetforeveryone.blogspot.com/
|
|
|
|
|
I'm not familiar with the webservice. Could you point me to a tutorial or sample application?
|
|
|
|
|
Try Google first and also try this article. And search codeproject for articles and google also when you receive an idea because you'll find everything you'll need.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
I have consulted google and I've reviewed the projects on the site but unfortunately I'm not sure how to integrate those tutorials into what I'm trying to do here. I basically need to call a function and return it's value to my program. And I also need to be able to modify it's value.
|
|
|
|
|
Nokoff wrote: I basically need to call a function and return it's value to my program. And I also need to be able to modify it's value.
You can write a webservice with 2 methods. A GetValue method and a SetValue method. You will be able to call these functions in your app to read a value and set a value.
It's just an idea.
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
Hello All,
I have a datagrid view on a windows form that I have working pretty well. I did not have the "MultiSelect" set to true so naturally the user was only able to make one row selection at a time and this worked fine.
Now the users have come up with a solution to trim their work time by being able to select multiple rows and have the processing done on the rows selected.
Here is my problem. I know how to retrieve the value in the first cell of the selected row but how do I go about selecting the values from the first cell in the subsequent rows that have been selected. I thought of using a 'for' statement but I am not sure how to move to the next row to retrieve the value of the next cell.
Thank you in advance for any help provided.
|
|
|
|
|
In general, things with a SelectedItems property can just be used like an array. So to get the first selected row, you just use
SelctedItems[0]
and for the second
SelectedItems[1]
etc. Im not sure if its called SelectedItems in a datagrid but it should work the same. I could be mistaken. If you've not got an answer by the time i get home, i'll check it out.
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
The SelectedRows property gives you an DataGridViewSelectedRowCollection on which you can iterate.
Hope it helps
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
Andrei,
I am sorry to be so bold as to state that I am not sure how I would implement the collection to iterate through. I am quite new to C# and coming from VB, collections are a different breed (for me at least.) I haven't gotten that far yet. Could you find yourself to provide a very small example of how to implement this particular collection. I did look to see if the SelectedRows Property included the Collection but couldn't find it. I did see something about GetEnumerator but I'm lost.
Thanks though.
F
|
|
|
|
|
I will give you an example, supposing you have a DataGridView called dgv
DataGridViewSelectedRowCollection collection = dgv.SelectedRows;
foreach (DataGridViewRow row in collection)
{
}
row is a DataGridViewRow with which you have work before...right? Of course you will have to place this code somewhere in an event, or function...you'll figure that part out.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
Andrei,
That was the ticket. After your response I researched it and now I have a good understanding of how this works. Again, thank you both for your responses.
Best regard,
F
|
|
|
|
|
Hi,
Consider the next situation
I Have this Attribute
<br />
[AttributeUsage(BlaBlaBla)]<br />
public class myattribute:Attribute<br />
{<br />
...<br />
...<br />
...<br />
}<br />
Now - Inside My Form
<br />
public class MyForm:Form<br />
{<br />
[myattribute]<br />
Button button1;<br />
<br />
Public MyForm()<br />
{<br />
button1 = new Button();<br />
}<br />
}<br />
now - using reflection - how can i get this attribute from button1?
the next gode does not work
<br />
Type Y = button1.GetType();<br />
object[] obj = T.GetCustomAttributes(typeof(myattribute),false);<br />
obj.Length is 0
(I Guess it because T.GetCustomAttributes returns the attributes of Type Button and not of its instance button1)
so... how can i get this attribute from button1?
Thanks
|
|
|
|
|
It's not working because your code is asking for all custom attributes on the Button class, not on your button1 field.
Here's how you should get custom attributes from a field:
Type myFormType = typeof(MyForm);
FieldInfo button1Field = myFormType.GetField("button1", BindingFlags.NonPublic | BindingFlags.Instance);
object[] customAttributes = button1Field.GetCustomAttributes(typeof(myattribute), false);
|
|
|
|
|
|
Rather than looking at the class, you have to look at the fields that belong to the class. Try this instead:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace Test
{
[AttributeUsage(AttributeTargets.All)]
public class myattribute : Attribute
{
public myattribute() : base() { }
}
public partial class Form1 : Form
{
[myattribute]
Button b1;
public Form1()
{
b1 = new Button();
this.Controls.Add(b1);
FieldInfo[] fis = this.GetType().GetFields(
BindingFlags.Instance | BindingFlags.NonPublic |
BindingFlags.Public);
foreach (FieldInfo fi in fis)
{
object[] o = fi.GetCustomAttributes(typeof(myattribute), true);
if (o.Length != 0)
{
Console.WriteLine("Hello from o");
}
}
}
}
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
Can anyone help?
I want to be able to drag and drop text into a Rich Text Edit or Memo type component but I want to drop the text at the position of the mouse cursor when the mouse button is released?
I have read a few articles so I can do drag and drop but how to drop at the mouse cursor position?
Thanks In Advance
|
|
|
|
|
I would suggest utilising the MouseUp event handler, and use HitTestInfo to find the coordinates of the pointer...
HitTest(e.X,e.Y)
Then set the cursor to this position, then perform your drop method at that position
Hope this helps
Give me strength, give me caffeine
|
|
|
|
|
Hey people
Was just wondering whether anyone knew whether this if statement is gonna be system dependent or not
e.KeyChar == 13, where e is a KeyPressEventArgs
Am trying to allow a text box to perform an action when return is pressed
The method works on my comptuer, but will it on another keyboard?
Cheers
Give me strength, give me caffeine
|
|
|
|
|
It's not system dependent because if you look at ASCII Table you can see that it's a standard notation for CR.
c#_keithy wrote: e.KeyChar == 13
My recommendation is to use the Keys enumeration to compare with e.KeyChar
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
Just found an mdn article on using Keypress events, which uses the following compare statement
e.KeyChar == (char)Keys.Return
KeyPressArticle[^]
Thanks for your input
Give me strength, give me caffeine
|
|
|
|
|
Hi,
I am able to list all available providers in the system presently windows using c#.
I can do that with the wql query i.e. select * from __Provider. But if i want to determine what type of provider it is, like say an instance provider or method provider etc then how do I determine that?
Also different classes use different types of providers like classes with events use event providers and those with use of methods use method provider.
But how to determine which event or method provider etc is being used by the class?
|
|
|
|
|
First og all.....I'm a newbee.....!!!
I need to make a service, that on a given time executes an application (APPL_1).
Furthermore I need to be able to tell the service to execute APPL_1 manually from another og my C# applications (APPL_2) by clicking a button.
So what I need is a way to "communicate" between the service and APPL_2 in order to execute APPL_1.
I hope the above isn't to cryptic.. *ss*
All kind of "help" would be appriciated.
/Lars Lie
|
|
|
|