Click here to Skip to main content
15,887,267 members
Home / Discussions / C#
   

C#

 
QuestionC# UnauthorizedAccessException Pin
Habekeinen29-Jan-12 2:08
Habekeinen29-Jan-12 2:08 
AnswerRe: C# UnauthorizedAccessException Pin
OriginalGriff29-Jan-12 3:02
mveOriginalGriff29-Jan-12 3:02 
GeneralRe: C# UnauthorizedAccessException Pin
Habekeinen29-Jan-12 3:49
Habekeinen29-Jan-12 3:49 
GeneralRe: C# UnauthorizedAccessException Pin
OriginalGriff29-Jan-12 3:53
mveOriginalGriff29-Jan-12 3:53 
AnswerRe: C# UnauthorizedAccessException Pin
Abhinav S29-Jan-12 19:04
Abhinav S29-Jan-12 19:04 
AnswerRe: C# UnauthorizedAccessException Pin
Bernhard Hiller29-Jan-12 20:44
Bernhard Hiller29-Jan-12 20:44 
QuestionQuestion about Chart in C# Pin
pongpanut28-Jan-12 20:31
pongpanut28-Jan-12 20:31 
AnswerRe: Question about Chart in C# PinPopular
OriginalGriff28-Jan-12 21:06
mveOriginalGriff28-Jan-12 21:06 
There are a number of "silly" things going on there which it would be worth fixing before you start looking at the meat of your problem:
C#
String idtoselect = row.Cells[0].Value.ToString();
String str1 = idtoselect.ToString();
Why?
idtoselect is already a string, so why convert it to a string in order to load it into another string? In fact you never reference idtoselect agains, so why not just use that throughout, where the name is a bit more meaningfull than str1?
C#
string sql2 = "select NAME_Product from Product where  Product.ID_Product = '"+str1+"' ";
Is a bad idea - do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
C#
while (rdr.Read())
{
    test = rdr["NAME_Product"].ToString();
}
test is a string - it can only hold a single value, so why use a loop? Use
C#
if (rdr.Read())
instead.
C#
CultureInfo ci = new CultureInfo("th-TH");
Does nothing at all unless you actually use it in a conversion.
C#
string sql = "SELECT * FROM Order1 where ID_Product = '"+str1+"' AND DATE_Order BETWEEN '" + dateTimePicker1.Value.ToString("s") + "' AND '" + dateTimePicker2.Value.ToString("s") + "' ";
Seriously, don't concatenate strings. You have the DateTime values as DateTime. SQL understands DateTime, and does not need it to be in any particular format. Unlike strings, where it does (SQL needs ISO format yyyy-MM-dd), and you aren't providing that, you are providing the short date form of your current culture.
C#
string sql = "SELECT * FROM Order1 where ID_Product = @ID AND DATE_Order BETWEEN @D1 AND @D2";
da = new SqlDataAdapter(sql, conn);
da.SelectCommand.Parameters.AddWithValue("@ID", idtoselect);
da.SelectCommand.Parameters.AddWithValue("@D1", dateTimePicker1.Value);
da.SelectCommand.Parameters.AddWithValue("@D2", dateTimePicker2.Value);


And you may find that if you do all that, your problem may magically disappear! I suspect it might...

BTW: Stop using the Visual Studio default names for things. dateTimePicker1, dateTimePicker2 don't mean a whole lot - try reading the above with them called startDate and endDate instead - see how much easier it is to read?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

GeneralRe: Question about Chart in C# Pin
pongpanut28-Jan-12 21:47
pongpanut28-Jan-12 21:47 
GeneralRe: Question about Chart in C# Pin
OriginalGriff28-Jan-12 21:49
mveOriginalGriff28-Jan-12 21:49 
GeneralRe: Question about Chart in C# Pin
pongpanut28-Jan-12 22:20
pongpanut28-Jan-12 22:20 
AnswerRe: Question about Chart in C# Pin
Luc Pattyn28-Jan-12 22:38
sitebuilderLuc Pattyn28-Jan-12 22:38 
GeneralRe: Question about Chart in C# Pin
pongpanut29-Jan-12 0:10
pongpanut29-Jan-12 0:10 
GeneralRe: Question about Chart in C# Pin
OriginalGriff28-Jan-12 23:08
mveOriginalGriff28-Jan-12 23:08 
GeneralRe: Question about Chart in C# Pin
pongpanut29-Jan-12 1:58
pongpanut29-Jan-12 1:58 
GeneralRe: Question about Chart in C# Pin
OriginalGriff29-Jan-12 2:06
mveOriginalGriff29-Jan-12 2:06 
GeneralRe: Question about Chart in C# Pin
pongpanut29-Jan-12 2:16
pongpanut29-Jan-12 2:16 
GeneralRe: Question about Chart in C# Pin
OriginalGriff29-Jan-12 2:58
mveOriginalGriff29-Jan-12 2:58 
AnswerRe: Question about Chart in C# Pin
Luc Pattyn29-Jan-12 8:35
sitebuilderLuc Pattyn29-Jan-12 8:35 
GeneralRe: Question about Chart in C# Pin
Luc Pattyn28-Jan-12 22:12
sitebuilderLuc Pattyn28-Jan-12 22:12 
GeneralRe: Question about Chart in C# Pin
pongpanut28-Jan-12 22:23
pongpanut28-Jan-12 22:23 
QuestionWriting source code in seperate files Pin
Fred 3427-Jan-12 22:27
Fred 3427-Jan-12 22:27 
AnswerRe: Writing source code in seperate files Pin
Richard MacCutchan27-Jan-12 22:37
mveRichard MacCutchan27-Jan-12 22:37 
GeneralRe: Writing source code in seperate files Pin
Eddy Vluggen27-Jan-12 23:44
professionalEddy Vluggen27-Jan-12 23:44 
GeneralRe: Writing source code in seperate files Pin
Richard MacCutchan28-Jan-12 0:19
mveRichard MacCutchan28-Jan-12 0:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.