While input of date - literal does not match format string - asp.net

I have this line of code in asp.net through which inserting date into a table
CMPI_EFF_DATE = cc.GetDataSet("SELECT TRM_EFF_STDT as TRM_EFF_STDT FROM TRM_MST WHERE TRM_CODE = " + ddlTrm.SelectedValue + "").Tables[0].Rows[0]["TRM_EFF_STDT"].ToString(),
and i am using oracle database . but while inserting data into it it show's an error
literal does not match format string

Is ddlTrm.SelectedValue string value? if it's true, I thing you should put value in quotes like this
"'" + ddlTrm.SelectedValue+"'"
Full example:
CMPI_EFF_DATE = cc.GetDataSet("SELECT TRM_EFF_STDT as TRM_EFF_STDT FROM TRM_MST WHERE TRM_CODE = '" + ddlTrm.SelectedValue+"'").Tables[0].Rows[0]["TRM_EFF_STDT"].ToString()

I think you are wrong here ddlTrm.SelectedValue + "")
It should be ddlTrm.SelectedValue )
CMPI_EFF_DATE = cc.GetDataSet("SELECT TRM_EFF_STDT as TRM_EFF_STDT FROM TRM_MST WHERE TRM_CODE = " + ddlTrm.SelectedValue).Tables[0].Rows[0]["TRM_EFF_STDT"].ToString(),

Related

Reading from a text file and then Write to the text file in same classic ASP script

<%
dim narrationCounter,logDateString,logDate, logTime,folderName,folderPath,logFolder2,month,day,year,txtFilePath
logDateString = Request.Form("logDateString")
logDate = Date()
folderName = "NarrationClickLog" & "_" & logDate
month = DatePart("m",Now())
day = DatePart("d", Now())
year = DatePart("yyyy",Now())
folderPath = "D:\iisroot\casecomments\CaseNarrationClickLog" + "_" & month & "_" & day & "_" & year
txtFilePath = folderPath + "\CaseNarrationClickLog.txt"
visitorIP=Request.ServerVariables("REMOTE_ADDR")
visitorUserName = Request.ServerVariables("REMOTE_USER")
visitorHost = Request.ServerVariables("remote_host")
set oFs = server.createobject("Scripting.FileSystemObject")
If Not oFs.FolderExists(folderPath) Then
set logFolder=oFs.CreateFolder(folderPath)
End If
' Extract last updated narration button click value from text file
if oFs.FileExists(txtFilePath) then
if oFs.GetFile(txtFilePath).size <> 0 then 'Get narrationCounterVal from log file
' open the file and Read it
set oTextFile = oFs.OpenTextFile(txtFilePath, 1 , true) 'forreading
ReadMe = oTextFile.ReadAll
Tab = split(ReadMe,vbcrlf)
i = ubound(Tab) - 2
paragraph=paragraph & Tab(i) & ""
Response.Write("Paragraph is : " + paragraph)
paragraphReverse = StrReverse(paragraph)
Response.Write( paragraphReverse )
' get the narration counter
narrationCounterPos = Split(paragraphReverse)
'Default delimiter is the space character..in this case Split at the Space before colon SO first element in array is narration counter number
narrationCounterVal = StrReverse(narrationCounterPos(0))
'Response.Write("Latest Narration Counter from text file is :- " + narrationCounterVal)
narrationCounter = narrationCounterVal + 1
oTextFile.Close
set oTextFile = nothing
WriteToLogFile(narrationCounter)
else ' Set narration Counter Value = 1 , A NEW FIRST Record entry.
narrationCounter = 1
WriteToLogFile(narrationCounter)
end if
Response.Write("Latest Narration Counter value :- " + narrationCounterVal)
Response.Write("file exists")
else
Response.Write("File does not exist")
end if
function WriteToLogFile(narrationCounter)
set oTextFileWrite = oFs.OpenTextFile(txtFilePath, 8, True) ' "D:\IISROOT\CaseComments\CaseNarrationClickLog.txt"
oTextFileWrite.WriteLine " User IP Address: " + visitorIP + " User Name: " + visitorUserName + " Clicks on DATE : " + logDateString + " are : " + narrationCounter
Response.Write("Text file path : -" + txtFilePath & " visitor IP : " & visitorIP & " User name: " & visitorUserName & " visitor host: " & visitorHost)
oTextFileWrite.Close
set oTextFileWrite = nothing
end function
oTextFile.Close
set oTextFile = nothing
oTextFileWrite.Close
set oTextFileWrite = nothing
set oFS = nothing
%>
This code must do the following:
Checks if folder exists, if not, create
Check if text file exists, If Yes then Read contents from text file in the above way, extract the narrationCounterVal variable value and then WRITE to the text file using the WritetoLogFile(narrationCounter) function
Problem: Just stuck. The folder and file get created BUT nothing gets written to it. I am also making sure that I close the oTextFile object used for opening file in Read mode before I call the Writetologfile function.

SQL Server Data type change from Numeric(7,3) to Varchar(20)

I have a field (dose_str) that needs to be changed from Numeric(7,3) to Varchar(20). I would like to know if there will be a need to change the query below (especially this portion SELECT (convert(varchar,cast(Prot_det.dose_str as float)) ) in the code of my application.
myCommand.CommandText = "
SELECT (convert(varchar,cast(Prot_det.dose_str as float)) + ' '
+ dose_unit + ' ' + dose_form_comment + ' ' + dose_mult) as Dose_str
from
Prot_det,
dosage_form
where
Protocol_num = '" & lblProtocol.Text & "' and
nsc_num = " & lstNSC.SelectedValue & " and
prot_det.dose_form = dosage_form.dose_form"
After changing the datatype of the column, you will be able to change this:
(convert(varchar,cast(Prot_det.dose_str as float))
to this:
(Prot_det.dose_str)
And I would recommend that you do.

How to select a row from a datatable by comparing trimmed data?

filteredrows = Server_Tables[i].Select("Servername='" + searchtext + "'");
The code above compares the data without trimming and selects matched rows.
So how to select rows with trimming?
Try this:
filteredrows = Server_Tables[i].Select("TRIM(Servername) ='" + searchtext.Trim() + "'");
Filter expression used in Datatable.Select supports TRIM function. I've also added Trim() to your entered values since spaces are possible there as well.
Trim searchtext variable;
filteredrows = Server_Tables[i].Select("TRIM(Servername)='%" + searchTerm + "%'");
To trim row values while retrieving with select method you can use;
filteredrows = Server_Tables[i].Select("Servername='%" + searchTerm.Trim() + "%'");
Do you need following;
filteredrows = Server_Tables[i].Select("Trim(Servername)='%" + searchtext.Trim() + "%'");

How to set dynamically the correct Dateformat in VB for SQL Query

Hello i have an sql query which uses a Dateformat. This code will run on different servers but every server have different dateformats. sometimes yyyy-MM-dd and sometimes yyyy-dd-MM.
I tried to read the userlanguage to choose the correct query. but it doesnt work properly.
Do you know any other good solution to solve my problem ?
Thanks in advance
Dim Systemsprache as String
Systemsprache = Request.UserLanguages(0)
If String.Compare(Systemsprache, "de-DE") = 0 Then
sqlcmd = "SELECT convert(varchar(8) , [VON],108) as [VON] ,convert(varchar(8) , [BIS],108) as [BIS] FROM [RESERVIERUNGRAUM] where RAUM_ID =" + hCurrRaumID.Value + " and VON >='" + Date.Parse(wiDateVON1.Value).ToString("yyyy-MM-dd") + "' and BIS <'" + Date.Parse(wiDateVON1.Value).AddDays(1).ToString("yyyy-MM-dd") + "'"
Else
sqlcmd = "SELECT convert(varchar(8) , [VON],108) as [VON] ,convert(varchar(8) , [BIS],108) as [BIS] FROM [RESERVIERUNGRAUM] where RAUM_ID =" + hCurrRaumID.Value + " and VON >='" + Date.Parse(wiDateVON1.Value).ToString("yyyy-dd-MM") + "' and BIS <'" + Date.Parse(wiDateVON1.Value).AddDays(1).ToString("yyyy-dd-MM") + "'"
End If
If I remember correctly, you can use the universal format '#yyyy-mm-dd#' regardless of the server default date format.

Crystal Report with Error : A number range is required here

I am using the crystal report, in that i am using code like below to show the SQL data into the crystal report,
string req = "{View_EODPumpTest.ROId} IN " + str + " AND " + "({View_EODPumpTest.RecordCreatedDate}>=date(" + fromDate.Year + " , " + fromDate.Month + " , " + fromDate.Day + ")" + "AND" + "{View_EODPumpTest.RecordCreatedDate}<=date(" + toDate.Year + " , " + toDate.Month + " ," + toDate.Day + " ))";
ReportDocument rep = new ReportDocument();
rep.Load(Server.MapPath("PumpTestReport.rpt"));
DateTime fromDate = DateTime.Parse(Request.QueryString["fDate"].ToString());
DateTime toDate = DateTime.Parse(Request.QueryString["tDate"].ToString());
CrystalReportViewer_PumpTest.ReportSource = rep;
//CrystalReportViewer1.SelectionFormula = str;
rep.RecordSelectionFormula = str;
CrystalDecisions.CrystalReports.Engine.TextObject from = ((CrystalDecisions.CrystalReports.Engine.TextObject)rep.ReportDefinition.ReportObjects["txtFrom"]);
from.Text = fromDate.ToShortDateString();
CrystalDecisions.CrystalReports.Engine.TextObject to = ((CrystalDecisions.CrystalReports.Engine.TextObject)rep.ReportDefinition.ReportObjects["txtTO"]);
to.Text = toDate.ToShortDateString();
//Session["Repo"] = rep;
CrystalReportViewer_PumpTest.RefreshReport();
after running my application it executes fine with no exception but such error i am getting,
A number range is required here. Error in File C:\DOCUME~1\Delmon\LOCALS~1\Temp\PumpTestReport {14E557A7-51B3-4791-9C78-B6FBAFFBD87C}.rpt: Error in formula . '{View_EODPumpTest.ROId} IN ['15739410','13465410'] AND ({View_EODPumpTest.RecordCreatedDate}>=date(2010 , 12 , 1)AND{View_EODPumpTest.RecordCreatedDate}<=date(2010 , 12 ,25 ))' A number range is required here.
error.
what i will do for this?
Please help,
Thanks in advance
You've not included the definition of 'str' in your code sample, but I'd guess that it's a comma-separated set of values. For Crystal to interpret this you have to put the value range inside [ and ], not the standard ( and ) you might use in SQL. Eg,
{View_EODPumpTest.ROId} IN [1,2,3,4,5,6]

Resources