Click here to Skip to main content
15,890,527 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionTrouble with IF...Then...ElseIf... Pin
big_D7-Jan-14 11:36
big_D7-Jan-14 11:36 
AnswerRe: Trouble with IF...Then...ElseIf... Pin
Bernhard Hiller7-Jan-14 20:49
Bernhard Hiller7-Jan-14 20:49 
GeneralRe: Trouble with IF...Then...ElseIf... Pin
big_D8-Jan-14 7:43
big_D8-Jan-14 7:43 
AnswerRe: Trouble with IF...Then...ElseIf... Pin
GuyThiebaut7-Jan-14 21:54
professionalGuyThiebaut7-Jan-14 21:54 
GeneralRe: Trouble with IF...Then...ElseIf... Pin
big_D8-Jan-14 7:44
big_D8-Jan-14 7:44 
QuestionDatagridView not display any data Pin
Biplob Singha Shee6-Jan-14 7:41
Biplob Singha Shee6-Jan-14 7:41 
AnswerRe: DatagridView not display any data Pin
Dave Kreskowiak6-Jan-14 7:55
mveDave Kreskowiak6-Jan-14 7:55 
AnswerRe: DatagridView not display any data Pin
Ron Beyer6-Jan-14 7:58
professionalRon Beyer6-Jan-14 7:58 
Try changing this:

VB
Dim sb As New StringBuilder
           sb.Append("SELECT ExpDate,ExpPurpose,Expenditure FROM expenditure WHERE ExpDate BETWEEN '" & DateFrom & "' AND '" & DateTo & "'")
           Dim dbcommand As New MySqlCommand
           Dim dbadapter As New MySqlDataAdapter
           Dim stdata As New DataTable
           dbcommand.Connection = conn
           dbcommand.CommandText = sb.ToString
           dbadapter.SelectCommand = dbcommand


To this:

VB
String sb = "SELECT ExpDate,ExpPurpose,Expenditure FROM expenditure WHERE ExpDate BETWEEN @StartDate AND @EndDate")
Dim dbcommand As New MySqlCommand
Dim dbadapter As New MySqlDataAdapter
Dim stdata As New DataTable
dbcommand.Connection = conn
dbcommand.CommandText = sb;
dbcommand.Parameters.AddWithValue("@StartDate", DateFrom)
dbcommand.Parameters.AddWithValue("@EndDate", DateTo)
dbadapter.SelectCommand = dbcommand


The problem is that the date strings are not properly formatted to return the right data in your SQL, since you are using the default ToString method instead of an actual format like yyyy-MM-dd. Using parameters will force the underlying data adapter to insert the correct strings for the values without you having to worry about formatting them. Additionally, this is preferred to avoid SQL injection attacks and cleaner code.
GeneralRe: DatagridView not display any data Pin
Biplob Singha Shee6-Jan-14 8:37
Biplob Singha Shee6-Jan-14 8:37 
GeneralRe: DatagridView not display any data Pin
Ron Beyer6-Jan-14 8:58
professionalRon Beyer6-Jan-14 8:58 
GeneralRe: DatagridView not display any data Pin
Biplob Singha Shee6-Jan-14 9:24
Biplob Singha Shee6-Jan-14 9:24 
GeneralRe: DatagridView not display any data Pin
Biplob Singha Shee9-Jan-14 4:56
Biplob Singha Shee9-Jan-14 4:56 
GeneralRe: DatagridView not display any data Pin
Ron Beyer9-Jan-14 5:13
professionalRon Beyer9-Jan-14 5:13 
GeneralRe: DatagridView not display any data Pin
Biplob Singha Shee9-Jan-14 6:28
Biplob Singha Shee9-Jan-14 6:28 
GeneralRe: DatagridView not display any data Pin
Biplob Singha Shee9-Jan-14 6:32
Biplob Singha Shee9-Jan-14 6:32 
GeneralRe: DatagridView not display any data Pin
Biplob Singha Shee9-Jan-14 6:52
Biplob Singha Shee9-Jan-14 6:52 
GeneralRe: DatagridView not display any data Pin
Dave Kreskowiak6-Jan-14 9:21
mveDave Kreskowiak6-Jan-14 9:21 
GeneralRe: DatagridView not display any data Pin
Biplob Singha Shee6-Jan-14 9:27
Biplob Singha Shee6-Jan-14 9:27 
QuestionCOM component Pin
dharmendra113-Jan-14 20:01
dharmendra113-Jan-14 20:01 
AnswerRe: COM component Pin
Richard MacCutchan3-Jan-14 22:38
mveRichard MacCutchan3-Jan-14 22:38 
QuestionIncorporating setup with other EXEs Pin
SPSandy2-Jan-14 20:27
SPSandy2-Jan-14 20:27 
AnswerRe: Incorporating setup with other EXEs Pin
Bernhard Hiller2-Jan-14 21:50
Bernhard Hiller2-Jan-14 21:50 
GeneralRe: Incorporating setup with other EXEs Pin
SPSandy2-Jan-14 23:21
SPSandy2-Jan-14 23:21 
GeneralRe: Incorporating setup with other EXEs Pin
Heriberto Lugo5-Jan-14 20:14
Heriberto Lugo5-Jan-14 20:14 
QuestionRecovering VB.NET code Pin
Tim Carmichael2-Jan-14 7:37
Tim Carmichael2-Jan-14 7:37 

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.