|
Welcome~
Tan Li
I Love KongFu~
|
|
|
|
|
Sounds to me like you should be using a set data structure, if you never need the duplicate strings.
At university studying Software Engineering - if i say this line to girls i find they won't talk to me
Dan
|
|
|
|
|
Thanks Dan!
But there is no such data structure in .Net, correct?
regards,
George
|
|
|
|
|
|
Thanks Dan!
Good stuff!
regards,
George
|
|
|
|
|
salam sir;
how can made c#.net messenger?
mohammedali
|
|
|
|
|
Most people would use a compiler to do that, and then write some code.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I think they would write code and then run it through the compiler. I may be wrong though. Google can help you decide that though.
|
|
|
|
|
*grin* yeah, I knew as I typed it that I had that backwards. I really meant, you start by getting an IDE.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Or a book? Maybe even an article[^] or two?
The weird part is, there was a similar question in vb.net and I posted a pretty simple copy and paste link of some code that, all that would be really needed is some UI modifications to suit his needs, but I doubt he would even get that far. Nevermind porting it over to C#. Funny stuff.
|
|
|
|
|
Christian Graus wrote: start by getting an IDE
No thanks.
|
|
|
|
|
Does that mean you take pride in writing code the slow way ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Absolutely, quality takes time.
Hand tools were good enough for my grandfather, they're good enough for me.
|
|
|
|
|
See, now I can't work out if you're joking or not.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Only partly. I see no reason to use VS and create all the horrible solution and project files and directories just to write and compile a simple console program.
Generally, for console programs and library routines, I use edit and compile with CSC.
I miss the days of Turbo Pascal and its ilk where it would simply build what you had open.
I'm hoping Leppie will add that to xacc.ide
|
|
|
|
|
Hi,
I don't know if this was more suited to the database message board or not but I think my question is more to do with my code rather than the database.
I have a basic table with a few columns. One of them is a Bit type and is effectively a flag. All I want to do is get the flag value for a given ID.
I've tried using an output parameter in a stored procedure but I don't know the best way of retrieving the flag value and converting it to a Boolean in code. I don't think a SqlDataReader is ideal because it's only one value I want to return.
ALTER PROCEDURE SP_UserValid
@ID INT,
@Valid BIT OUTPUT
AS
SET NOCOUNT ON;
SET @Valid = (SELECT [Valid] FROM tUsers WHERE ID = @ID)
Here's my code:
SqlConnection connection = new SqlConnection(_ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_UserValid";
cmd.Parameters.Add(new SqlParameter("@ID", userID));
cmd.Parameters.Add(new SqlParameter("@Valid", bValid));
cmd.Parameters["@Valid"].SqlDbType = SqlDbType.Bit;
cmd.Parameters["@Valid"].Direction = ParameterDirection.InputOutput;
connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close()
Thanks for looking
|
|
|
|
|
bool isValid = Convert.ToBoolean(cmd.Parameters["@Valid"].Value)
only two letters away from being an asset
|
|
|
|
|
You could also use:
bool isValid = Convert.ToBoolean(SqlCommand.ExecuteScalar());
I'd probably have used
select @Valid = [Valid] FROM tUsers WHERE ID=@ID
But what you have is fine.
Lastly, you may want to use ParameterDirection.Output for the @Valid parameter since there isn't a value being passed in...
|
|
|
|
|
Thanks to both you guys
I ended up making my SP simpler:
...
SELECT [Valid] FROM tUsers WHERE ID = @ID
...
I then used ExecuteScalar() and it works great!
One question though, what if the value returned from the DB is NULL ? I've set the column to disallow NULL values but I thought it should probably have something in the code too, just in case
Lastly, is there a best practice for this sort of thing in terms of performance?
|
|
|
|
|
If the column is a bit data type then it will always return 0/1 never a null.
If the col is an int (I do this) then put a default on the table def of 0 and you will never get null returned
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi Mycroft,
"If the column is a bit data type then it will always return 0/1 never a null" => This is a false statement. I tried using the following query and in all three executions the IsActive field is null.
DECLARE @tb TABLE(UID INT ,IsActive BIT)
INSERT INTO @tb (UID) SELECT 1
SELECT * FROM @tb
DECLARE @tb TABLE(UID INT ,IsActive BIT)
INSERT INTO #Temp (UID) SELECT 1
SELECT * FROM #Temp
DROP TABLE #Temp
DECLARE @tb TABLE(UID INT ,IsActive BIT)
INSERT INTO Temp (UID) SELECT 1
SELECT * FROM Temp
DROP TABLE Temp
please correct me if i am wrong.
Mouli.
|
|
|
|
|
Ah you are right, either I made a dramatic mistake or this may have changed at some time. There used to be a time when bool/bit could not be null.
Still stick a contraint on the table forcing it to 0, that'll fix the issue and will save you writing code in the BL to check for null.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
PROBLEM:
The problem I am having is, given the layout of the Microsoft template for developing a Windows App, I need to know what is the best way of implementing a method to make modifications to a control on my main form (Form1).
NECESSARY BACKGROUND:
A basic Windows program comes up with a Form1.cs and a Program.cs (I have renamed Program.cs to FileOrganizer.cs).
In FileOrganizer.cs there is a Main method.
Within this Main method is "Application.Run(new Form1());".
What I want to do (within another method of the FileOrganizer class) is to update a control programmatically.
The fact that Form1 is "run" the way it is (i.e., using "Application.Run"), makes it so there is no reference to an object. Because there is no way to reference the Form1 object I don't know of a way to modify one of the controls on Form1.
If I create a global reference to Form1 and then create a "new" instance of Form1 (within Main) I receive an error ("Error 4 An object reference is required for the non-static field, method, or property 'FileOrganizer.FileOrganizer.mainForm'").
My implementation is as follows:
namespace FileOrganizer
{
public class FileOrganizer
{
private Form1 mainForm;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
mainForm = new Form1();
Application.Run(mainForm);
I understand that this error occurs because the Main method is static although I don't understand why.
One way of making this work is by doing the following:
public class FileOrganizer
{
private Form1 mainForm;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
FileOrganizer fg = new FileOrganizer();
}
public FileOrganizer()
{
mainForm = new Form1();
mainForm.Visible = true;
But I am not sure if this is the proper way to do what I need to do (i.e., provide a way to modify a control on Form1 in another method of the FileOrganizer class).
So, given the static Main limitation, what is the proper way to implement the code so that controls on Form1 can be modified?
modified on Tuesday, December 23, 2008 4:36 PM
|
|
|
|
|
Mike Bluett wrote: update a control programmatically.
What do you mean? What are trying to accomplish? Typically you would create a method in the form class to call and manipulate the control from there.
only two letters away from being an asset
|
|
|
|
|
I have updated my original posting in order to try and make it more clear. Hope this helps.
|
|
|
|