|
My first guess would be to Open() dbArticles before you instantiate the "cmd" object. You're creating it and assigning it to the connection before the connection is active.
|
|
|
|
|
Ok...like you said I did it this way:
if (dbArticles.State == ConnectionState.Closed)
dbArticles.Open();
OleDbCommand cmd = new OleDbCommand("select type_id from proArticles where _id= " + ArticlesTypes[1], dbArticles);
but it still does not work!
|
|
|
|
|
The order you associate the connection with your command makes no difference whatsoever. Association wise, it doesn't matter whether or not you open the connection and then create the command or create the command then open the connection. Although you should always attempt to open the connection just before you execute your command (preferably in the statement before) because you want the connection to be open as short a time as possible.
What I would suggest you do is break the split command apart from the ExecuteScalar part. In other words, read the value into a string - and then, if the string isn't null attempt the split. Combining operations like this can lead you into a lot of bother.
One more thing - try using a parameterised query rather than a concatenated query. It reduces the risk of you falling prey to a SQL Injection attack. Clickety[^]
|
|
|
|
|
Run the project and debug this method. Set the breakpoint on the string[] ptu line of code and when you hit the breakpoint, check the state of the connection to see if it's open or not. Also, try putting some exception handling round this line to see what exception is really being thrown. Don't guess at what the error is, do some debugging for yourself.
|
|
|
|
|
I am looking for a c# programmer to help me with improving a project. I have done the programming my self (pretty well commented and easy to understand). It is working ok but I need help from an expert to improve and clean up the programming i also want to make an installer. Ofcource you get paid and you can work from anywhere in the world.
The project is developed in c# express 2005, SQL, Source Grid, and php (I manage the php my self)
Best Regards
Andreas
Contact: programmerATbrollopDOTinfo
|
|
|
|
|
You should put this in the job forum, Job Board[^]
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi all,
I have this:
Byte[] buff = new Byte[256];
Does it exist any function which can clear whole buffer or I have to write my own code?
Thanks.
daavena
|
|
|
|
|
in .net arrays are automatically initialized to zero by the compiler. Unlike C++, no manual action is necessary.
--
Join the Campaign to Help Stamp Out and Abolish Redundancy
The preceding is courtesy of the Bureau of Unnecessarily Redundant Repetition Department.
|
|
|
|
|
Thanks for response.
I use:
NetworkStream stream = tcp.GetStream();
stream.Read(buff, 0,buff.Length);
.....
somewhere in the code again:
stream.Read(buff, 0,buff.Length);
Do I have to clear buff?
Thanks.
daavena
|
|
|
|
|
Yes and no. When you call the Read() function, it overwrites the existing array with the new data. The trick is, if there's not enough data to fill it, it does not clear the rest.
The trick is, the Read() function will RETURN to you the actual number of bytes it put in the buffer. So when you're processing the results, only look at the first n characters (Where n is the value returned).
Of course, if you're just sending the entire buffer into another function, you'll have to manually clear the rest of the buffer (Or manually clear the whole thing first).
|
|
|
|
|
Hi Ian,
As you said, Read() function doesn't clear the buffer.
I use Read() function witch will return to me n number of bytes it put in the buffer.
I also wrote a simple function for clearing buffer.
Thanks
daavena
|
|
|
|
|
Like the above post states, they are initialized to zero. There's also not much point in clearing a buffer, you just overwrite it.
But, if you must, just use a for loop:
for(int i=0; i<buff.Length; i++){
buff[i] = 0;
}
My current favourite word is: PIE!
I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for.
-The Undefeated
|
|
|
|
|
Try it
buff.Initialize();
It initialize the array by calling the default constructor for value type byte
Bye
|
|
|
|
|
Hi,
this doesn't work. In the buff still stays old values.
daavena
|
|
|
|
|
You are right
Here is wath MSDN say about Initialize()
This method is designed to help compilers support value-type arrays; most users do not need this method. It must not be used on reference-type arrays.
If the Array is not a value-type Array or if the value type does not have a default constructor, the Array is not modified.
The value-type Array can have any lower bound and any number of dimensions.
it can't work. Sorry
|
|
|
|
|
Hi ovrgarriga,
I wrote a simple function for this.
Thanks for help.
|
|
|
|
|
The same way as you would clear a room... fart.
|
|
|
|
|
Extension methods can and will be abused, apparently.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
And there's no such thing as an entirely defensive weapon.
|
|
|
|
|
Array.Clear(array, index, length) ???
|
|
|
|
|
Sorry guys...bear with me if I am asking a silly question here. I am only a beginner in C#.
My question is that:
public frmTopic(string[] Articles) //What does this mean? Why should we declare the string[] array inside the parenthesis.
{
InitializeComponent();
}
|
|
|
|
|
T4AMD wrote: public frmTopic(string[] Articles)
Looks to me that the frmTopic (form?) constructor is taking a string array as an argument. It's not declaring the array.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
string[] is an argument that is a string of arrays.
T4AMD wrote: Why should we declare the string[] array inside the parenthesis.
The form is probably using the array of strings somewheres. It doesn't have to be an array of a string, it can be any datatype.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Similarly, you may also see:
static void Main(string[] args) {<br />
<br />
}
when the application is executed, windows passes an array of strings. For example, when you click on a word document, it runs word.exe and passes the path to the word document as one of the strings in the array. This string is read, and the correct file opened.
Just as in your example, when you create this form, you pass it an array of strings that represent the articles within a topic (i assume, based on the naming)
It will then do something with these strings.
Really its just like any other function or method that requires some input.
My current favourite word is: PIE!
I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for.
-The Undefeated
|
|
|
|
|
I'd like to write a remote desktop app for use simply on local networks. I'm at a loss for where to start concerning items like screen captures and transfers. I know I'll be using socket programming (I'm researching that at the moment) to transfer these things, but that's about all I know so far.
Any thoughts on where to start and the best route to take? Thanks!
|
|
|
|