VB.NET - query

Asked By pradeep kumar
03-Feb-12 02:23 AM
Dim q As String = "Select * from Leave_status where FacultyID='" & Session("UserID") & "' And FromDate > ='" & txtfrdate.Text & "' And ToDate < = '" & txttodt.Text & "' And Status in('Approved','Rejected','RequestSent')"

in this query within month date will be given it will displayed....
but when i given one date for this month and another dare for next month but it will not displayed ... so gv me the solution plz
  Reena Jain replied to pradeep kumar
03-Feb-12 02:27 AM
hi,

to get the record between two dates, here is the query

Select * from table1 where Convert(datetime, mydate, 103)  between
Convert(datetime, @Fromdt, 103) and Convert(datetime, @Todt, 103)

Hope this will help you
  dipa ahuja replied to pradeep kumar
03-Feb-12 02:36 AM
Make sure you are passing the date in format which database accepts that mean if table storing the date in mm/dd/yyyy then you have to pass the date in that format only. 

string q = "Select * from Leave_status where (FacultyID='" + Session("UserID") + "') And (FromDate > ='" 
  + txtfrdate.Text + "') And (ToDate < = '" + txttodt.Text 
  + "') And Status in('Approved','Rejected','RequestSent')";



  Web Star replied to pradeep kumar
03-Feb-12 02:45 AM
Actually the problem is when you are using date comparison that doesn't work with string date that operation should be done on datetime datatype so you must convert datetime type when put where condition in query
  Web Star replied to pradeep kumar
03-Feb-12 02:46 AM
Also the matter is date format if your system having setting with dd/mm/yyyy and if you are passing data in format of mm/dd/yyyy than such type of query giving wrong result
In Counting The NumBer Of Days  In Counting The NumBer Of Days
06-Feb-12 12:22 AM
When Counting The Number Of Days Between Two Days So Here Sunday, Saturday And Holidays Not Count how to do that Please Help Me
Create New Account
help
Date validation for 2 dates with dd / mm / yyyy hi, in vb.net i kept 2 textbox controls namely fromdate and todate and 1 search button, so based on fromdate and todate report will come now i want to validate for the 2 textboxes with TextBox1_CalendarExtender" runat = "server" Enabled = "True" Format = "dd-MMM-yyyy" TargetControlID = "TextBox1" > < / cc1 : CalendarExtender > Now whichever date user will select it will be in the formate dd / MMM / yyyy First convert the date entered in Textbox to datetime DateTime departDate, returnDate; departDate = DateTime.Parse(flightDepartureDateTextBox.Text); returnDate = DateTime try { departDate = DateTime.Parse(flightDepartureDateTextBox.Text); } catch (Exception ex) { feedbackLabel.Text = "Invalid data entry: Departure Date is invalid. " + "Enter a valid date, for example: 01 / 20 / 2006"; return; } try { returnDate = DateTime
avoid repeating same code VB.NET Hi all, I am trying to query records from a table Records based on various pages in Form1. Regardless of these criteria, the query should always include a query by date, which is entered as StartDate (textbox1) and EndDate (textbox2). I have written the code below between('" + TextBox1.Text + "' AND '" + TextBox1.Text + "')" ; Stored Procedure Try this way: ALTER PROCEDURE dbo.BetweenDates ( @FromDate datetime , @ToDate datetime ) AS select * from table1 where orderDate between @FromDate and @ToDate RETURN If you have such type of dynamic requirement depends upon runtime dynamically created at runtime based on the passing parameter. Create PROCEDURE dbo.BetweenDates ( @tblname varchar(200), @FromDate datetime, @ToDate datetime ) AS begin declare @sqlquery varchar(4000) set @sqlquery = 'select * from ' +@tblname + ' where orderDate between AND ''' + @FromDate + ''' and ''' + @ToDate + '''' exec(@sqlquery) end so in above sp you can pass table name from date and to date that will give you result based on that parameter hope this helps
report based on dates Hi, I want to display a crystal report based on from date & to date conditions. I am storing these two dates within some strings in .aspx page like start date & enddate. How to write selectionformula using these strings. Can any one please tell me how Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim fromdate As String = Request.QueryString("fromdate") Dim todate As String = Request.QueryString("todate") Dim myParameterFields As New ParameterFields Dim myParameterField As New ParameterField Dim myParameterField1 As New ParameterField Dim myDiscreteValue As New ParameterDiscreteValue myParameterField.ParameterFieldName = "@FromDate" 'FromDate is the name of the parameter field created in your RPT file myDiscreteValue.Value = fromdate myParameterField.CurrentValues.Add(myDiscreteValue) myParameterFields.Add(myParameterField) myParameterField1.ParameterFieldName = "@ToDate" 'ToDate is the name of
rEGARDING REPORT PARAMETER SQL Server I AM TRYING TO SEND PARAMETER VALUE TO REPORT USING VB.NET CODE BUT ITS NOT ASSIGNING THE VALUE TO THE REPORT PARAMETER. I USING THAT CODE Sub btnGenerateReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGenerateReport.Click Try 'FromDate = Format(CType(FromDate, Date), "yyyy-MM-dd") 'ToDate = Format(CType(ToDate, Date), "yyyy-MM-dd") txtRepoFromDate.Text = Format(CType("2006-10-01", Date), txtRepoToDate.Text = Format(CType("2006-10-11 Date), strServerPath = "http: / / harishjagannath / ReportServer" strReportPath = " / RS_P2Reports / RS_P2_KeyPerfsrpt" rptParam(0) = New Microsoft.Reporting.WebForms.ReportParameter("FromDimTimeTheDate
using crystal report hi guyz, m working on crystal reports using vb.net and oracle 10g as backend. . .i want to pass parameters to the report at run time. . say for example if i bind my report with say table T having item, date, amount as fields. . . . now at runtime i have 2 blank text boxes . . in first textbox i got to write the starting date and in other the end date. . now when i press a button say "buttonreport" only those records that are within the As New ParameterFields Dim fromDateField As New ParameterField Dim fromDateValue As New ParameterDiscreteValue fromDateField.ParameterFieldName = "fromdate" fromDateValue.Value = txtFromData.Text fromDateField.CurrentValues.Add(fromDateValue) inputs.Add(fromDateField) CrystalReportViewer1 .ParameterFieldInfo = inputs Or use the SetParameterValue method of the report. Dim fromDate As String = txtFromDate.Text myReport .SetParameterValue("parameter name fromDate) Hope this helps. hey i want to fetch records within a given range. . ur code