|
Firstly, if at all possible, you should use parameterised queries, and if not, you must escape the contents of those text boxes before creating the query string. At the moment, if those are free text boxes, there is a huge SQL injection hole in this code.
Secondly, you should be using a DateTimePicker or similar for the dates, and using myDateTimePicker.Value.ToString("yyyy-MM-dd") to get them in database format. Edit from the subthread below: If you are using parameterised queries, you should (of course) pass the date as a DateTime. The string formatting is only if you are building a query string. Ideally you should use a numeric text box type as well but inexplicably that doesn't exist in the standard framework.
Thirdly, I suspect the immediate cause of the problem is that the dates are not in a valid format. See what the string you are actually creating really looks like, and compare it to a static query that works.
modified on Thursday, July 21, 2011 1:02 PM
|
|
|
|
|
BobJanova wrote: using myDateTimePicker.Value.ToString("yyyy-MM-dd") to get them in database
format
No, don't do that; just put the DateTime in a parameter.
|
|
|
|
|
I did start my answer with 'if at all possible, use a parameterised query'. Yes, that is better if it's possible (and it almost always is).
|
|
|
|
|
Yes, but as a DateTime, not as a String.
|
|
|
|
|
I meant that formatter to only be used in the case that the OP couldn't use parameterised queries, so he was building up the query string (where obviously everything must be a string). But you are right, I didn't make that clear, so I'll go and edit my initial message. Thanks!
|
|
|
|
|
Remove the single quotes for text fields if using alphabets in text. And # symbol to insert date.
|
|
|
|
|
i tried to use a new two parameters:
m_insert_cmd2.Parameters.Add("@DateStart", MySqlDbType.DateTime).Value = this.dateTimePicker1.Text;
m_insert_cmd2.Parameters.Add("@DateEnd", MySqlDbType.DateTime).Value = this.dateTimePicker2.Text;
and tried like this:
m_insert_cmd2.Parameters.Add("@DateStart", MySqlDbType.DateTime).Value = this.dateTimePicker1.Text.ToString();
m_insert_cmd2.Parameters.Add("@DateEnd", MySqlDbType.DateTime).Value = this.dateTimePicker2.Text.ToString();
the same problem is communicat:
String was not recognized as a valid DateTime.
my full query look like:
m_insert_cmd2 = new MySqlCommand("INSERT INTO tb_rezerwacja (kwota, ilosc_osob, w_tym_ilosc_dzieci, data_od, data_do, FK_pokoj_id, FK_zamowienie_id) VALUES (' 345', '3', '3', @DateStart, @DateEnd, @pokoj_id, @zamowienie_id)", m_conn);
on form i add 2 dateTimepickers like u see and in MySQL database the date fields are in Date format...
modified on Wednesday, July 20, 2011 3:00 PM
|
|
|
|
|
|
Hello Experts,
If i have a string "abc". then how can i get the shown output
a
b
c
ab
bc
ac
abc
In this output i do't need of ba or cab or cba.
Thanks
If you can think then I Can.
|
|
|
|
|
Is this, what you are looking for?
string value="abc";
string result=string.Empty;
for(int i=0;i<=value.Length-1;i++)
{
result+=value[i].ToString()+"\n";
}
for(int i=0;i<=value.Length-1;i++)
{
if(i<value.Length-1)
{
result+=value[i].ToString()+value[i+1].ToString()+"\n";
}
else
{
result+=value[0].ToString()+value[value.Length-1].ToString()+"\n"+value;
}
}
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
The Length of value is not fixed for 3
it can be increase and the result will be change according to input.
then how can i do that.
If you can think then I Can.
|
|
|
|
|
Length of string is dynamic too on my example.
Did you try my code to see result?
Which is result for you if the string is "abcd"
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
the result by program is :
a
b
c
d
ab
bc
cd
abcd
But Required result is :
a
b
c
d
ab
bc
cd
da
bd
abc
bcd
dab
....
abcd
..etc
If you can think then I Can.
|
|
|
|
|
Backtracking . You can search google to more detail .
I can it useful for you . Thanks !!
|
|
|
|
|
Homework question?
Should the output contain ACB? or strictly ordered?
|
|
|
|
|
A double iteration over the input string with position and substring length :
string str = "anystring";
for (int x = 1; x <= str.Length; x++)
{
for (int y = 0; y <= str.Length - x; y++)
{
Console.WriteLine(str.Substring(y, x));
}
}
Cheers
|
|
|
|
|
Hello Estys,
Thanks for your solution.But it is missing values.
Input : ABC
Output :
A
B
C
AB
BC
CA // Missing Value
SO pls provide the solution for that.
If you can think then I Can.
|
|
|
|
|
I didn't see the "CA" value, ouch!
Can you give an example of the expected output if the input is "ABCD"?
Or perhaps describe the situation in words? I suspect you're going to need some recursive algorithm.
Cheers
|
|
|
|
|
Estys wrote: input is "ABCD"?
Same question I asked
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
Blue_Boy wrote: Same question I asked
Great minds think alike .
If you can read this, you don't have Papyrus installed
|
|
|
|
|
CA wasn't in the initial spec, but AC was. The OP needs to better define what the problem actually is (and why he wants to solve it beyond 'my homework says so').
|
|
|
|
|
You're right of course from a professional viewpoint.
Some people, non-native english speakers, have trouble finding the right phrasing of the question though, which leads to this kind of confusion.
I took a look at his profile, very interesting.
Personally, I usually like solving these kindergarten puzzles, even if it sounds like homework .
Cheers
|
|
|
|
|
Based on his/her profile description, he/she should be able to solve that problem.
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
|
But he isn't asking for permutations..
|
|
|
|