phone type in computed property - vb.net

In the following code sample the property type for [MainSwitchBoardPhone] is "Phone". When I make the computed ClinicHospitalAddress property the summary property for the Entity I would like the phone number to show up in a data entry screen with (555) 555-5555 format rather than merely a string. i.e. 5555555555. Is there a way to do this?
Private Sub ClinicHospitalAddress_Compute(ByRef result As String)
' Set result to the desired field value
result = [ClinicHospital] & " " & [StreetAddress] & ", " & _
[City] & " " & [MainSwitchBoardPhone]

Try:
result = String.Format("{0} {1}, {2} (###) ###-####" _
, [ClinicHospital] _
, [StreetAddress] _
, [City] _
, Convert.ToInt64([MainSwitchBoardPhone]) _
)
Edit: Added Convert.ToInt64

as follows:
result = [ClinicHospital] & " " & [StreetAddress] & ", " & _
[City] & " " & Format([MainSwitchBoardPhone],"(###) ###-####")

Related

Allow datagrid control to accept decimal values vb.net

Hi I have a datagrid control(not datagridview control) placed in a windows form(Vb) it have 10 columns. I am trying to input decimal value in one of the column but it is resetting its value. For ex:
I have 31 in a cell and trying to edit it to 20.5 as soon as i change the cell it resets back to 31. If i input any integer value like 21 it accepts the value.
_da = New OleDbDataAdapter("SELECT EMPDETAILPERSONAL.EMPCODE, EMPDETAILPERSONAL.EMPNAME, EMPDETAILPERSONAL.EMPDEPT, EMPDETAILPERSONAL.EMPDOB, 0 AS AGE, " & _
" EMPDETAILPERSONAL.EMPDOJ, EMPDETAILPERSONAL.EMPPANNP, " & Date.DaysInMonth(selYear, selMonth) & " AS NOD, " & Date.DaysInMonth(selYear, selMonth) & " AS LD, CSDEPT.CSDEPTNAME, EMPDETAILPERSONAL.EMPDESG, " & _
" EMPDETAILPERSONAL.EMPSALACC, EMPDETAILPERSONAL.EMPPFACC, EMPDETAILPERSONAL.EMPPPFACC, EMPDETAILPAYROLL.EMPBASIC, EMPDETAILPAYROLL.EMPGPA, CDbl(0) AS CONS, " & _
" EMPDETAILPAYROLL.EMPDA, EMPDETAILPAYROLL.EMPHRA, EMPDETAILPAYROLL.EMPTA, EMPDETAILPAYROLL.EMPMISCADD, EMPDETAILPAYROLL.EMPGRSAL, " & _
" EMPDETAILPAYROLL.EMPPFMEM, EMPDETAILPAYROLL.EMPITAX, EMPDETAILPAYROLL.EMPMISCDED, EMPDETAILPAYROLL.EMPNETSAL, " & _
" IIf(EMPLOAN.LOANAMTINST Is Null,0,EMPLOAN.LOANAMTINST) AS LOAN, CSDESIGNATION.CSDESGNAME, EMPDETAILPAYROLL.EMPINCDATE, EMPDETAILPAYROLL.EMPINCAPP, " & _
" EMPDETAILPAYROLL.EMPBASIC AS o_basic, EMPDETAILPAYROLL.EMPGPA AS o_gpa, EMPDETAILPAYROLL.EMPDA AS o_da, " & _
" EMPDETAILPAYROLL.EMPHRA AS o_hra, EMPDETAILPAYROLL.EMPTA AS o_ta, EMPDETAILPAYROLL.EMPPFMEM AS o_pf, EMPDETAILPAYROLL.EMPPFEMPL AS o_pf_e, " & _
" EMPDETAILPAYROLL.EMPPPFEMPL AS o_ppf_e, EMPDETAILPAYROLL.EMPPFEMPL, EMPDETAILPAYROLL.EMPPPFEMPL, " & _
" EMPDETAILPAYROLL.EMPMISCADD AS o_add, EMPDETAILPAYROLL.EMPITAX AS o_tax, EMPDETAILPAYROLL.EMPMISCDED AS o_less, " & _
" IIf(EMPLOAN.LOANAMTINST Is Null,0,EMPLOAN.LOANAMTINST) AS o_loan, CDbl(0) AS EMPCONTRI,EMPDETAILPAYROLL.EMPCCA AS CCA,EMPDETAILPAYROLL.EMPMEDALL AS MEDALL,EMPDETAILPAYROLL.EMPOTHERALL AS OTHERALL,EMPDETAILPAYROLL.EMPESI AS ESI,EMPDETAILPAYROLL.EMPGPF AS GPF,EMPDETAILPAYROLL.EMPPAYSCALE AS PAYSCALE " & _
" FROM EMPLOAN RIGHT JOIN (((EMPDETAILPERSONAL INNER JOIN CSDEPT ON EMPDETAILPERSONAL.EMPDEPT = CSDEPT.CSDEPTID) " & _
" INNER JOIN EMPDETAILPAYROLL ON (EMPDETAILPERSONAL.EMPDESG = EMPDETAILPAYROLL.EMPDESG) AND (EMPDETAILPERSONAL.EMPDEPT = EMPDETAILPAYROLL.EMPDEPT) " & _
" AND (EMPDETAILPERSONAL.EMPCODE = EMPDETAILPAYROLL.EMPCODE)) INNER JOIN CSDESIGNATION ON EMPDETAILPERSONAL.EMPDESG = CSDESIGNATION.CSDESGID) " & _
" ON EMPLOAN.EMPCODE = EMPDETAILPERSONAL.EMPCODE " & _
" WHERE EMPDETAILPERSONAL.EMPDOL Is Null ORDER BY IIF(EMPDETAILPERSONAL.EMPDESG = 1, '10','20') + EMPDETAILPERSONAL.EMPCODE", _con)
_da.Fill(_dtEmp)
dgEmp.DataSource = _dtEmp
There is nothing written in cellchanged event. Even value is resetting before triggering cellchanged event. Please help. Thanks
You should make sure that the corresponding column of your datatable is not of an integer type. If the given column is some kind of integer this condition is then reflected in the datagrid column and when you enter values with decimals they are casted back to integer.

item cannot be found in the collection corresponding to the requested name or ordinal

My code gives the following error. How can I correct this?
Item cannot be found in the collection corresponding to the requested name or ordinal
ElseIf Me.chkItem.Checked = True Then
Dim CheckNumber As String = ""
Dim CheckRef As String = ""
dsvoucheritem.Clear()
DSVoucher_Expense.Clear()
DSVoucher_Check.Clear()
Try
Me.lstCV.Items.Clear()
strDiscount = Nothing
rec.Open("select billpaymentcheckline.txnnumber, billpaymentcheckline.txndate" _
& ", billpaymentcheckline.payeeentityreffullname" _
& ", billpaymentcheckline.amount, billitemline.itemlineitemreffullname" _
& ", billitemline.memo" _
& ", billpaymentcheckline.appliedtotxndiscountamount" _
& ", billpaymentcheckline.appliedtotxnrefnumber, billpaymentcheckline.bankaccountreffullname" _
& ", billpaymentcheckline.appliedtotxndiscountaccountreffullname" _
& ", billpaymentcheckline.appliedtotxntxndate, billpaymentcheckline.appliedtotxnamount" _
& ", billpaymentcheckline.refnumber, account.AccountNumber from (billitemline inner join" _
& " billpaymentcheckline on billitemline.refnumber=billpaymentcheckline.appliedtotxnrefnumber) left outer join" _
& " account on billitemline.APAccountreflistid=account.listid where" _
& " billpaymentcheckline.bankaccountreflistid='" &Me.lblBankID.Text & "' and" _
& " billpaymentcheckline.refnumber between '" & CInt(Me.txtRefFR.Text)
& "' and '" & CInt(Me.txtRefTO.Text) & "'", con, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly)
It's saying it doesn't recognize one of your column names. Double check all of them. You can also try removing fields until you find the culprit.
memo is a reserved word in Access SQL.
Try billitemline.[memo]

Last 'OR' statement Ignored in OLEDB command

I'm trying to filter a OLEDB command by having multiple 'OR' statements work on a single database field but the last in the chain gets ignored and doesn't return anything.
I have a work around for now with a #null request that returns "DBNull.value" but if I remove "[doctype] = #null" from below it ignores "[doctype] = doctype3"
& "WHERE [doctype] = #doctype OR [doctype] = #doctype2 OR [doctype] = #doctype3 OR [doctype] = #null " _
I can increase or decrease the 'OR Statements' as I like but it is always the last 'OR Statement' that is ignored.
I've tried putting the 'OR statements' in brackets but then it returns nothing, or I'm doing it wrong.
I'm looking for simply why the last 'or statement' is ignored in the oledbcommand string but if you can improve any code I've wrote please do, but explain to me why/how.
Where they are used (Every other value has DBNull.value for testing purposes)
f_doctype = "MS"
f_doctype2 = "TMS"
f_doctype3 = "CS"
With cmdaRefresh.Parameters
.AddWithValue("doctype", CType(f_doctype, String))
.AddWithValue("doctype2", CType(f_doctype2, String))
.AddWithValue("doctype3", CType(f_doctype3, String))
.AddWithValue("null", DBNull.Value)
.AddWithValue("docnum", DBNull.Value)
.AddWithValue("docrev", DBNull.Value)
.AddWithValue("matname", DBNull.Value)
.AddWithValue("status", DBNull.Value)
.AddWithValue("actionreq", DBNull.Value)
.AddWithValue("createdby", DBNull.Value)
.AddWithValue("createddate", DBNull.Value)
.AddWithValue("finalby", DBNull.Value)
.AddWithValue("finaldate", DBNull.Value)
End With
Dim cmdRefresh As New OleDbDataAdapter(cmdaRefresh)
'open connection
myconnection.Open()
'read and fill dataset for gridview
cmdRefresh.Fill(dsRefresh, tbl_string.tablename)
'close connection
myconnection.Close()
'fill datagrid with values from database and alter column headers to match criteria
With dg_speclog
.DataSource = dsRefresh.Tables(0)
.RowHeadersVisible = False
.Columns(0).HeaderCell.Value = "Category"
...
End With
Full 'oledbcommand' creation
Dim cmdaRefresh As OleDbCommand = New OleDbCommand(" SELECT [doctype], [docnum], [docrev], [matname], [status], [actionreq], [createdby], [createddate], [finalby], [finaldate] " _
& "FROM " & tbl_string.tablename & " " _
& "WHERE [doctype] = #doctype OR [doctype] = #doctype2 OR [doctype] = #doctype3 OR [doctype] = #null " _
& "AND [docnum] = #docnum " _
& "AND [docrev] = #docrev " _
& "AND [matname] = #matname " _
& "AND [status] = #status " _
& "AND [actionreq] = #actionreq " _
& "AND [createdby] = #createdby " _
& "AND [createddate] = #createddate " _
& "AND [finalby] = #finalby " _
& "AND [finaldate] = #finaldate " _
& "ORDER BY [docnum] ASC, [docrev] ASC " _
, myconnection)
You need to use IS NULL to check for null values (in most, perhaps all, databases, null does not equal null, so you need to use the IS operator instead). This also means you don't need all those parameters.
Depending on how you intend to combine the [doctype] IS NULL check with the other null checks, you may also need to wrap the ORs in parentheses, since AND may have higher precedence than OR.
Dim cmdaRefresh As OleDbCommand = New OleDbCommand(
" SELECT [doctype], [docnum], [docrev], [matname], [status], [actionreq], [createdby], [createddate], [finalby], [finaldate] " _
& "FROM " & tbl_string.tablename & " " _
& "WHERE ([doctype] = #doctype OR [doctype] = #doctype2 OR [doctype] = #doctype3 OR [doctype] IS NULL) " _
& "AND [docnum] IS NULL " _
& "AND [docrev] IS NULL " _
& "AND [matname] IS NULL " _
& "AND [status] IS NULL " _
& "AND [actionreq] IS NULL " _
& "AND [createdby] IS NULL " _
& "AND [createddate] IS NULL " _
& "AND [finalby] IS NULL " _
& "AND [finaldate] IS NULL " _
& "ORDER BY [docnum] ASC, [docrev] ASC " _
, myconnection)
If the[doctype] IS NULL check belongs with the other NULL checks then you don't need the parens.
Found the reason why it wasn't working. Somewhere during my search I read that DBNull.value would return anything from the database when used with a .addwithvalue statement (which might of confused the whole thing). Which is not correct, it returns anything that has a value of nothing as in no white space or value. Which is why [doctype] IS NULL gave the same issue as above, it does the same thing, I think.
What I was looking for was a way to search through my [doctype]'s and return any value from the other database fields without having to specify anything 'for testing'
The statement I was looking for was [docnum] LIKE '%' this is called a Wildcard. A wildcard character can be used to substitute for any other character(s) in a string, so that mean anything is returned. However if the database field is of value Null then a IS NULL statement is still require, hence my [finalyby] & [finaldate] alterations below.
What I've came up with now is:
'CHANGED (dataadapter > command)
Dim cmdaRefresh As OleDbCommand = New OleDbCommand(" SELECT [doctype], [docnum], [docrev], [matname], [status], [actionreq], [createdby], [createddate], [finalby], [finaldate] " _
& "FROM " & tbl_string.tablename & " " _
& "WHERE [doctype] IN (#doctype, #doctype2 ,#doctype3) " _
& "AND [docnum] LIKE '%' " _
& "AND [docrev] LIKE '%' " _
& "AND [matname] LIKE '%' " _
& "AND [status] LIKE '%' " _
& "AND [actionreq] LIKE '%' " _
& "AND [createdby] LIKE '%' " _
& "AND [createddate] LIKE '%' " _
& "AND ([finalby] LIKE '%' OR [finalby] IS NULL) " _
& "AND ([finaldate] LIKE '%' OR [finaldate] IS NULL) " _
& "ORDER BY [docnum] ASC, [docrev] ASC " _
, myconnection)
Thank you to who helped.

SQL Query works in MS-Access but cannot implement it in vb.net form

The block of code immediately following (given to me by a stackoverflow solver) works perfectly in MS-Access. I'm trying to convert it to work in a vb.net form accessing the very same MS-Access database. I get an error and cannot see my mistake. Are there any vb.net coders that can see what I'm doing wrong. The first block of code works in MS-Access and is the code I'm trying to convert. And the second block of code is my conversion attempt.
SELECT at.animalID, amt.milestoneType
FROM
animals_Table at
LEFT JOIN
(
SELECT animalID, milestoneType
FROM animalMilestones_Table
WHERE milestoneType = 'Intake'
) amt
ON at.animalID = amt.animalID
Now, my conversion attempt:
dim selectAnimal as string
selectAnimal = "SELECT at.animalID, amt.milestoneType" & _
" FROM animals_Table at" & _
" LEFT JOIN" & _
" (" & _
" SELECT animalID, milestoneType" & _
" FROM animalMilestones_Table" & _
" WHERE milestoneType = '" & "Intake" & "'" & _
" ) amt" & _
" ON at.animalID = amt.animalID"
The error code I get is
!ErrorInfo.GetDescription failed with E_FAIL(0x80004005)
It appears that ACE.OLEDB doesn't like at as a table alias. Try this instead
Dim selectAnimal As String
selectAnimal = "SELECT atbl.animalID, amtbl.milestoneType" & _
" FROM animals_Table atbl" & _
" LEFT JOIN" & _
" (" & _
" SELECT animalID, milestoneType" & _
" FROM animalMilestones_Table" & _
" WHERE milestoneType = '" & "Intake" & "'" & _
" ) AS amtbl" & _
" ON atbl.animalID = amtbl.animalID"

ERROR [22P02] ERROR: invalid input syntax for integer: "";

Never seen such error:
ERROR [22P02] ERROR: invalid input syntax for integer: ""; Error while executing the query
Creating table:
Public Function PrimkCreate(ByVal myPrimkTable As String, ByVal nCon As OdbcConnection) As Integer
Dim ans As Integer
Dim cCommand As OdbcCommand = New OdbcCommand("CREATE TABLE IF NOT EXISTS " + myPrimkTable + "(" & _
"prm_id int NOT NULL, " & _
"pkni text, " & _
"pdatum text, " & _
"pdatumnaplate text, " & _
"pdanaodgode int, " & _
"puldok text, " & _
"puldokbroj text, " & _
"pdatumk text, " & _
"pvrijemek text, " & _
"pdobid int, " & _
"pdoboib text, " & _
"pnabc double precision, " & _
"purab double precision, " & _
"ppdv double precision, " & _
"ppnak double precision, " & _
"pprodc double precision, " & _
"pvrstaprimke int, " & _
"pzapisniktekst text, " & _
"prez text, " & _
"CONSTRAINT " & myPrimkTable & "_pkey PRIMARY KEY(prm_id))", nCon)
ans = cCommand.ExecuteNonQuery()
cCommand.Dispose()
Return ans
End Function
Update code:
Public Function update_LPrimk(ByRef primk As Integer, ByVal mCon As OdbcConnection) As Integer
Dim retval As Integer
Dim uCmd As OdbcCommand = New OdbcCommand("UPDATE " & myPrimkTable & " SET " & _
"prm_id=" & primk & ", " & _
"pkni='" & prm.pKni & "', " & _
"pdatum='" & prm.pDatum & "', " & _
"pdatumnaplate='" & prm.pDatumNaplate & "', " & _
"pdanaodgode=" & prm.pDanaodgode & ", " & _
"puldok='" & prm.pUlDok & "', " & _
"puldokbroj='" & prm.pUlDokBroj & "', " & _
"pdatumk='" & prm.pDatumk & "', " & _
"pvrijemek='" & prm.pVrijemek & "', " & _
"pdobid='" & prm.pDobID & "', " & _
"pdoboib='" & prm.pDobOib & "', " & _
"pnabc='" & Replace(prm.pNabc.ToString, ",", ".") & "', " & _
"purab='" & Replace(prm.pURab.ToString, ",", ".") & "', " & _
"ppdv='" & Replace(prm.pPdv.ToString, ",", ".") & "', " & _
"ppnak='" & Replace(prm.pPnak.ToString, ",", ".") & "', " & _
"pprodc='" & Replace(prm.pProdc.ToString, ",", ".") & "', " & _
"pvrstaprimke=" & prm.pVrstaPrimke & ", " & _
"pzapisniktekst='" & prm.pZapisnikTekst & "', " & _
"prez='" & prm.pRez & "' " & _
"WHERE prm_id=" + primk.ToString, mCon)
retval = uCmd.ExecuteNonQuery()
uCmd.Dispose()
Return retval
End Function
Query looks exactly like this:
UPDATE primke SET prm_id=1, pkni='U', pdatum='07.01.2013', pdatumnaplate='10.01.2013',
pdanaodgode=3, puldok='ghkzug gugug', puldokbroj='jkhk', pdatumk='', pvrijemek='',
pdobid='', pdoboib='', pnabc='0', purab='0', ppdv='0', ppnak='0', pprodc='0',
pvrstaprimke=0, pzapisniktekst='', prez='' WHERE prm_id=1
I have many tables where I run similar commands but have never seen such an error.
What might be the problem?
I would advice to read the chapter Constants in the manual. It's a brief and informative read.
The cause for the error message is that '' is an empty string that has no representation in a numeric type like integer.
#a_horse_with_no_name: To be precise, '0' is a string constant to PostgreSQL that can be cast to integer just as well as it can be cast to text, only text is the default for string constants. Consider this demo:
CREATE TEMP TABLE t (i int);
INSERT INTO t VALUES (1);
INSERT INTO t VALUES ('2'); -- single row inserts to make sure ..
INSERT INTO t VALUES ('3'::int); -- .. type is not coerced to type
INSERT INTO t VALUES (4::bigint); -- .. of first row by VALUES expression.
INSERT INTO t VALUES (5::numeric);
INSERT INTO t VALUES (6);
UPDATE t SET i = '0' WHERE i = '6';
SELECT * FROM t;
SQL Fiddle.