Not exists or minus
I have 2 big table. And I want to get records on table A that is not exists on table B yet.
Which method should I use?
table A (30 millions)
noOrder
name
address
index on table A : noOrder unque index
table B (50 millions)
keyNo
noOrder
info
composite index on table B : keyNo, noOrder, info (1,2,3) unique
composite index on table B : noOrder, keyNo (1,2) not unique
NB: indexes on table B are unchangeable while indexes on table A could be adjustable (may add or remove)
Thanks n Regards
yup but I prefer to get some opinions before I really execute each method and have it on explain plan.You don't have to execute the query to get an explain plan.
EXPLAIN PLAN FOR SELECT ....
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY)
You're almost certainly looking for full table scans of both tables and a hash anti-join, by the way. It may not matter whether you use an outer join or a corre3lated subquery as the optimizer may transform the latter into the former in this case (I just had a very similar situation myself with row counts in the billions).
I'd shy away from the MINUS in this case. I don't think you'll get as efficient a plan and there's an implicit DISTINCT in there that you don't need.
Similar Messages
-
Why not exists and minus give different result
HI,
I am writing thes query by using two different operators they should give me the same output but they dont. Please can anybody explain why they give different output.
query 1
SQL> SELECT COUNT(*) FROM
2 (select orig_idx
3 from rel15_au_poi a
4 MINUS
5 SELECT ORIG_IDX
6 FROM REL14_1_AU_POI_INTERM B) ;
COUNT(*)
244312
query 2
SQL> select count(*)
2 from rel15_au_poi a
3 where not exists
4 (select null from rel14_1_au_poi_interm b where a.orig_idx=b.ORIG_IDX) ;
COUNT(*)
245341
best Regards,Because you have duplicates in rel15_au_poi which are counted with exists and removed with minus.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries004.htm#sthref3147
MINUS Example
The following statement combines results with the MINUS operator, which returns only unique rows returned by the first query but not by the second:
SELECT product_id FROM inventories
MINUS
SELECT product_id FROM order_items; -
Minus operator versus 'not exists' for faster SQL query
Hi everybody,
Does anyone know if rewriting a query to use the MINUS operator instead of using NOT EXISTS in the query is faster, giving all else is the same?
Thanks very much!
Bill Loggins
801-971-6837
[email protected]It really depends on a bunch of factors.
A MINUS will do a full table scan on both tables unless there is some criteria in the where clause of both queries that allows an index range scan. A MINUS also requires that both queries have the same number of columns, and that each column has the same data type as the corresponding column in the other query (or one convertible to the same type). A MINUS will return all rows from the first query where there is not an exact match column for column with the second query. A MINUS also requires an implicit sort of both queries
NOT EXISTS will read the sub-query once for each row in the outer query. If the correlation field (you are running a correlated sub-query?) is an indexed field, then only an index scan is done.
The choice of which construct to use depends on the type of data you want to return, and also the relative sizes of the two tables/queries. If the outer table is small relative to the inner one, and the inner table is indexed (preferrable a unique index but not required) on the correlation field, then NOT EXISTS will probably be faster since the index lookup will be pretty fast, and only executed a relatively few times. If both tables a roughly the same size, then MINUS might be faster, particularly if you can live with only seeing fields that you are comparing on.
For example, if you have two tables
EMPLOYEE
EMPID NUMBER
NAME VARCHAR2(45)
JOB VARCHAR2(45)
HIRE_DATE DATE
and
RETIREE
EMPID NUMBER
NAME VARCHAR2(45)
RET_DATE DATEIf you wanted to see if you had retirees that were not in the employee table, then you could use either MINUS or NOT EXISTS (or even NOT IN, but you didn't ask). However you could possibly get different results.
SELECT empid,name
FROM retirees
MINUS
SELECT empid,name
FROM employeeswould show retirees not in the emp table, but it would also show a retiree who had changed their name while retired. A safer version of the above using MINUS would be
SELECT empid,name
FROM retirees
WHERE empid IN (SELECT empid
FROM retirees
MINUS
SELECT empid
FROM employees)A full scan of retirees, a full scan of employees (Assuming indexes on both, then maybe an index fast full scan) and two sorts for the minus, at best an index probe then table access by rowid on retirees, possibly a full scan of retirees for the outer query.
Assuming that employees is indexd on empid then
SELECT empid,name
FROM retirees
WHERE NOT EXISTS (SELECT 1
FROM employees
WHERE retirees.empid = employees.empid)requires a full scan of retirees and an index access into employees index for each row.
As with most things SQL, the only real way to tell is to benchmark.
HTH
John -
Phone number appearing in Favorites list but does not exist in Contacts
I have an iPhone 4S, running iOS 5.1.1 (9B206).
About two weeks ago (not really sure when I noticed) a phone number appeared at the bottom of my Favorites list. The number is for a person that I deleted from Contacts some months ago. The number is not in the Contact list anywhere, the contact does not exist. I've tried recreating the contact (and Favorites then shows the name) and then deleting the contact, and its still there in the Favorites list.
There is a facetime icon next to the number. If I turn off Facetime, the number disappears.
Any ideas welcome.Go under your phone icon, then under the favorites tab. Look in the top left hand corner of the screen and there should be an edit button. Tap it, and then tap the red delete/minus icon to delete it from your favorites list.
-
Basic NOT EXISTS query not returning any results
DB Version: 10gR2
One of our tables in the test schema is having less number of columns than the PROD shema.
To determine which are missing columns in this table in Test schema i did the following.
-----In Test Schema
CREATE TABLE XYZ2
(COL1 NUMBER); ----------only one column
SQL > CREATE TABLE tables_test_list AS SELECT TABLE_NAME,COLUMN_NAME FROM USER_TAB_COLS;
Table created.--- In the prod schema
SQL> CREATE TABLE XYZ2
2 (COL1 NUMBER,
3 COL2 NUMBER ----------- same table name with an extra column
4 );
Table createdAnd from the PROD schema i execute the following SQL to determine what are the columns that are missing in the TEST schema
select column_name from User_Tab_Cols outer
where table_name='XYZ2'
and not exists (select 1 from TEST_SCHEMA.tables_test_list inner where outer.TABLE_NAME=inner.TABLE_NAME )But the above query is not returning any results. Any idea why?Actually, the example from the link I posted earlier:
[email protected]> (
2 select 'IN T1, NOT T2', column_name,data_type,data_length
3 from user_tab_columns
4 where table_name = 'T1'
5 MINUS
6 select 'IN T1, NOT T2', column_name,data_type,data_length
7 from user_tab_columns
8 where table_name = 'T2'
9 )
10 UNION ALL
11 (
12 select 'IN T2, NOT T1', column_name,data_type,data_length
13 from user_tab_columns
14 where table_name = 'T2'
15 MINUS
16 select 'IN T2, NOT T1', column_name,data_type,data_length
17 from user_tab_columns
18 where table_name = 'T1'
19 )
20 / -
Wrong query is getting generated in WHERE NOT EXISTS with group by clause
Query is getting generated wrongly in where not exists section when i use group by function.Please prvoide me any clue to over come the problem.
/* DETECTION_STRATEGY = NOT_EXISTS */
INSERT /*+ APPEND */ INTO STG_ETL.I$_DCMT_TIMEZONE_LOOKUP
TZ_OFFSET,
ADT_CRT_DT,
ADT_UPDT_DT,
IND_UPDATE
SELECT * FROM (
SELECT
to_number(KOFAX.RECEIVED_TZ) TZ_OFFSET,
min(sysdate) ADT_CRT_DT,
min(sysdate) ADT_UPDT_DT,
'I' IND_UPDATE
FROM ESTG.FLAT_FIL_DMS_KOFAX KOFAX
WHERE (1=1)
And (KOFAX.LD_DT = ( select MAX(LD_DT) from ESTG.FLAT_FIL_DMS_KOFAX INNER
where INNER.ENGAGEMENT=KOFAX.ENGAGEMENT
and INNER.KOFAX_FILE_NM = KOFAX.KOFAX_FILE_NM
AND INNER.IM_CUST_ID = KOFAX.IM_CUST_ID
and INNER.BATCH_ID=KOFAX.BATCH_ID)
AND
(TO_DATE(KOFAX.LD_DT)>=TO_DATE(SUBSTR('#WAREHOUSE.P_EDW_LAST_RUN',1,10),'YYYY-MM-DD'))
And (substr(KOFAX.RECEIVED_TZ,1,1) <> '+')
Group By to_number(KOFAX.RECEIVED_TZ)
) S
WHERE NOT EXISTS (
SELECT 'X'
FROM EDW.DCMT_TIMEZONE_LOOKUP T
WHERE T.TZ_OFFSET = S.TZ_OFFSET AND
)Easiest fix for you would be to change the detection_strategy on the IKM from NOT_EXISTS to either :
MINUS
-- Try this out, it should work, it will give the same data through the equiverlant steps.
NONE
-- This will load all incoming data into your I$ table, there will be more rows to crunch in the following 'Flag Rows for Update' step, it might give incorrect results potentially - you will have to test it.
So try MINUS first, failing that, see if NONE gives you what you want in your target.
Are you inserting only new data or updating existing data? -
Subquery table is not existed ?
I got compiler error, "dept" in sub query is not existed, actually I have defined it.
Thanks.
select dept.department_id, dept.department_name
from hr.departments dept right OUTER JOIN hr.employees emp on (dept.department_id = emp.department_id)
where dept.department_id in (select dept.department_id from dept minus select emp.department_id from emp)
SQL Error: ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"Hi,
Any join is "an extension of a row to another table ... based on key, row by row".
I don't understand what you mean by "just rows of A will go right and extend to B table".
Rows from the table to the left of (that is, before) "LEFT OUTER JOIN" will be included, even if they do not have a matching row in the table to the right.
Rows from the table to the right of (that is, after) "RIGHT OUTER JOIN" will be included, even if they do not have a matching row in the table to the left.
departments RIGHT OUTER JOIN employeesis equivalent to
employees LEFT OUTER JOIN departmentsBoth of the above mean that rows from employees will be included even if they have no matching row in departments.
departments LEFT OUTER JOIN employeesis equivalent to
employees RIGHT OUTER JOIN departmentsBoth of the above mean that rows from departments will be included even if they have no matching row in employees.
This WHERE-clause
where deptartments.department_id in
select dept.department_id
from deptartments
minus
select emp.department_id
from employees
)means that only department_ids that are found in departments, but are not found in employees, will be included. If you are using the WHERE-clause above, the main query should not include any mention of the employees table.
if you need more help, post a few rows of the results you want to get from the hr tables, and an explanation.
Edited by: Frank Kulash on Dec 8, 2008 9:33 PM -
Correlated Subqueries, NOT EXISTS & Anti Joins - Clarification
I am a bit confused now regarding correlated subqueries and the NOT EXISTS operator (I had originally thought I understood but am all mixed up now!)
I was reading around and have gathered that if one were to use EXISTS that this isnt the preferred method, and that the query should actually be re-written as a join (im guessing INNER JOIN) to improve performance.
NOT EXISTS is also not a recommended method from what I read as well.
Correlated subqueries in general are not recommended for performance issues, since the subquery needs to be executed once for every row returned by the outer query.
I was reading up on anti joins, and found that a lot of people referred to anti joins with the use of NOT EXISTS and a correlated subquery, which if my above understanding is correct is super bad in performance as it combines two things that people dont recommend.
I was wondering for anti joins, is there any other way to write them besides a NOT EXISTS with a correlated subquery?
Essentially what would be the most efficient way of writing an anti join? Or when Im trying to find all the rows that are NOT a common match between two tables.Hi,
chillychin wrote:
I am a bit confused now regarding correlated subqueries and the NOT EXISTS operator (I had originally thought I understood but am all mixed up now!)That's easy to understand! This is a topic that does not lend itself to easy, general solutions. So much depends on the circumstances of a particular query that you can never honestly say anything like "EXISTS is bad".
I was reading around and have gathered that if one were to use EXISTS that this isnt the preferred method, and that the query should actually be re-written as a join (im guessing INNER JOIN) to improve performance. It depends. EXISTS and joins do different things. For example, when you have a one-to-many relationship, joining can increase the number of rows. Even if the join is faster than EXISTS, you may have the additional cost of doing a GROUP BY or SELECT DISTINCT to get just one copy of each row.
NOT EXISTS is also not a recommended method from what I read as well.
Correlated subqueries in general are not recommended for performance issues, since the subquery needs to be executed once for every row returned by the outer query.There's a lot of truth in that. However, results of coirrelated queries can be cached. That is, the system may remeber the value of a correlation variable and the value it retuned, so the next time you need to run the sub-query for the same value, it will just return the cached result, and not actually run the query again.
Remember that performance is only one consideration. Sometimes performance is extremely important, but sometimes it is not important at all. Whether a query is easy to understand and maintain is another consideration, that is sometimes more important than performace.
The optimizer may re-write your code in any case. When perforance really is an issue, there's no substitute for doing a EXPLAIN PLAN, finding out what's making the query slow, and addressing those issues.
I was reading up on anti joins, and found that a lot of people referred to anti joins with the use of NOT EXISTS and a correlated subquery, which if my above understanding is correct is super bad in performance as it combines two things that people dont recommend. It's actually only one thing that the people who don't recommend it don't recommend. EXISTS sub-queries are always correlated. (Well, almost always. In over 20 years of writing Oracle queries, I only remember seeing one uncorrelated EXISTS sub-query that wasn't a mistake, and that was in a forum question that might have been hypothetical.) Nobody worth listening to objects to EXISTS because it is EXISTS, or to a correlated sub-query because it is correlated. They object to things because they are slow (or confusing, or fragile, but you seem to be concerned with performance, so let's just say slow for now.) If someone tires to avoid an EXISTS sub-query, it precisely because the sub-query is correlated, and that is only an objection because they suspect the correlation will make it slow.
I was wondering for anti joins, is there any other way to write them besides a NOT EXISTS with a correlated subquery?As the name implies, you can use a join.
SELECT d.*
FROM scott.dept d
LEFT OUTER JOIN scott.emp e ON d.deptno = e.deptno
WHERE e.deptno IS NULL
;is an anti-join, showing details about the departments that have no employees.
Essentially what would be the most efficient way of writing an anti join? Or when Im trying to find all the rows that are NOT a common match between two tables.Anytime you can use EXISTS, you can also use IN, or a join. Personally, I tend to use the in the reverse of that order: I'll generally try it with a join first. If that looks like a problem, then I'll try IN. The query above can also be done like this:
SELECT *
FROM scott.dept
WHERE deptno NOT IN (
SELECT deptno
FROM scott.emp
WHERE deptno IS NOT NULL -- If needed
;Failing that, I'll try EXISTS.
Sometimes other methods are useful, too. For example, if we only need to know the deptnos that exist in scott.dept but not scott.emp, and no other information about those departments, then we can say:
SELECT deptno
FROM scott.dept
MINUS
SELECT deptno
FROM scott.emp
; -
I have three select statements
1)(select rolename,StartDate from roleuser where roleuser in (select oprid from sysadm.psoprdefn where emplid = '00064764')
minus
select rolename,StartDate from roleuser where roleuser = 'IT_Manager')
2)select rolename,StartDate from roleuser where roleuser in (select oprid from sysadm.psoprdefn where emplid = '00064764')
and rolename not in ( select rolename from roleuser where roleuser = 'IT_Manager')
3)select rolename,StartDate from roleuser where roleuser in (select oprid from sysadm.psoprdefn where emplid = '00064764')
and not exists ( select rolename from roleuser where roleuser = 'IT_Manager')
the first and second return 3 rows (correct)
the not exists return 0 what is wrongselect rolename,StartDate from roleuser where roleuser in (select oprid from sysadm.psoprdefn where emplid = '00064764')
and not exists ( select rolename from roleuser where roleuser = 'IT_Manager')
Obviously it returns no rows found
not exists will excute based on true /false
not exists ( select rolename from roleuser where roleuser = 'IT_Manager') will be false based on your earlier results. and this is with "and" condition to query
there will be no rows found/ -
hi my requirement is
id column exists in all tables means
view v , tables A,B,C
i want to copmare like..
the id's which are available in V and not available in the three tables A,B,C
is this correct one or any simplify
select id from v
where not exists(select id from a where a.id=v.id)
and not exists(select id from b where b.id=v.id)
and not exists(select id from c where c.id=v.id)
thanksbpat wrote:
You are welcome.
Just one small comment on the solution, since we do not require any sort of sorting, I would prefer to use UNION ALL.Bpat:
I would probably test it both ways. Because of the minus, there is going to be two sort uniques in there somewhere. Each half of the minus has to be sorted and distincted before the minus can be done.
I used your sample to generate real tables, just to eliminate the effects of the hierarchical query, and it looks to me like, at least for a small sample set, union or union all are exactly the same, right down to the plan_id.
SQL> SELECT id
2 FROM t_data1 t1
3 minus
4 (select id from t_data2
5 union
6 select id from t_data3
7 union
8 select id from t_data4);
Execution Plan
Plan hash value: 2968485990
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 20 | 650 | 12 (84)| 00:00:01 |
| 1 | MINUS | | | | | |
| 2 | SORT UNIQUE | | 20 | 260 | 3 (34)| 00:00:01 |
| 3 | TABLE ACCESS FULL | T_DATA1 | 20 | 260 | 2 (0)| 00:00:01 |
| 4 | SORT UNIQUE | | 20 | 650 | 12 (84)| 00:00:01 |
| 5 | UNION-ALL | | | | | |
| 6 | TABLE ACCESS FULL| T_DATA2 | 5 | 65 | 2 (0)| 00:00:01 |
| 7 | TABLE ACCESS FULL| T_DATA3 | 10 | 130 | 2 (0)| 00:00:01 |
| 8 | TABLE ACCESS FULL| T_DATA4 | 15 | 195 | 2 (0)| 00:00:01 |
Note
- dynamic sampling used for this statement
Statistics
0 recursive calls
0 db block gets
12 consistent gets
0 physical reads
0 redo size
588 bytes sent via SQL*Net to client
488 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
5 rows processed
SQL> SELECT id
2 FROM t_data1 t1
3 minus
4 (select id from t_data2
5 union all
6 select id from t_data3
7 union all
8 select id from t_data4);
Execution Plan
Plan hash value: 2968485990
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 20 | 650 | 12 (84)| 00:00:01 |
| 1 | MINUS | | | | | |
| 2 | SORT UNIQUE | | 20 | 260 | 3 (34)| 00:00:01 |
| 3 | TABLE ACCESS FULL | T_DATA1 | 20 | 260 | 2 (0)| 00:00:01 |
| 4 | SORT UNIQUE | | 20 | 650 | 12 (84)| 00:00:01 |
| 5 | UNION-ALL | | | | | |
| 6 | TABLE ACCESS FULL| T_DATA2 | 5 | 65 | 2 (0)| 00:00:01 |
| 7 | TABLE ACCESS FULL| T_DATA3 | 10 | 130 | 2 (0)| 00:00:01 |
| 8 | TABLE ACCESS FULL| T_DATA4 | 15 | 195 | 2 (0)| 00:00:01 |
Note
- dynamic sampling used for this statement
Statistics
0 recursive calls
0 db block gets
12 consistent gets
0 physical reads
0 redo size
588 bytes sent via SQL*Net to client
488 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
5 rows processedEven a simple two table minus gets 2 sorts.
SQL> SELECT id
2 FROM t_data1 t1
3 minus
4 select id from t_data2;
15 rows selected.
Execution Plan
Plan hash value: 1776821228
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 20 | 325 | 6 (67)| 00:00:01 |
| 1 | MINUS | | | | | |
| 2 | SORT UNIQUE | | 20 | 260 | 3 (34)| 00:00:01 |
| 3 | TABLE ACCESS FULL| T_DATA1 | 20 | 260 | 2 (0)| 00:00:01 |
| 4 | SORT UNIQUE | | 5 | 65 | 3 (34)| 00:00:01 |
| 5 | TABLE ACCESS FULL| T_DATA2 | 5 | 65 | 2 (0)| 00:00:01 |
Note
- dynamic sampling used for this statement
Statistics
0 recursive calls
0 db block gets
6 consistent gets
0 physical reads
0 redo size
668 bytes sent via SQL*Net to client
488 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
15 rows processedJohn -
Display records that do not exist in another
Hi
I have two tables with one more than 2,00,000 and another 1,00,000 records. Both have one common filed ID. I wanan display allt eh records in table A that do not exist in table B. If i use 'not in', the system hangs. Is there anyother way to do this?
ThanksI would use SomeoneElse's and Centinul's idea before trying this, but ...
Outer join, filtering out rows where the join column isn't NULL on the outer side. If you can get this method to work it probably won't be efficient. I liked SomeoneElse's ideas best, but Centinul's idea of the MINUS is good too.
Edited by: riedelme on May 8, 2009 12:01 PM -
Hi,
What would be the alternative for the below query by using not exists .
select cust_name from cust_info where cust_name not in( select distinct cust_name from cust_details where status = 'CURRENT')
Thanksit gives you all possible alternatives and ways tooptimize the query
Is it? I've actually seen a couple tools that do that - Quest and Leccotech come to mind. they would actually rewrite a query hundreds, if not thousands, of different ways - using every hint, even ones that had no reason to be used (and using different hint combinations), using different join orders (with the ordered hint), rewriting subqueries to joins, to inline views, to scalar subqueries in the select list, etc, etc (possibly even giving the MINUS rewrite). but the tools had no way to know which rewrite was optimal, so it would then just execute each and every one, which could take several days (considering that some of the rewrites were terrible).
so yeah, I think I'll hold onto that tuning guide for just a while longer ;) -
Hi All !
I've created a mapping based on following query. In the mapping first I've joined(join1) da and db tables and as a next step used
minus set operator. The result set joined (join2) to da table to get the rest of columns from da. The last step is union set operator.
The result set from join2 and db table unioned and target table is loaded. But I'm not satisfied with a performance.
Is there another way to do that?
select distinct
a1||';'||a2
from da where not exists
(select ' ' from db where b1=a1)
union
select distinct
b1||';'||b2
from dbHi,
"not exists" subqueries can usually be re-written as outer-joins, and then you can use the Joiner operator.
In your example:
select distinct
a1||';'||a2
from da where not exists
(select ' ' from db where b1=a1)
union
select distinct
b1||';'||b2
from db
can be rewritten as:
select distinct
a1||';'||a2
from da
,db
where db.b1(+) = da.a1
and db.b1 is null
union
select distinct
b1||';'||b2
from db
Regards,
Gerton -
If image file not exist in image path crystal report not open and give me exception error problem
Hi guys my code below show pictures for all employees
code is working but i have proplem
if image not exist in path
crystal report not open and give me exception error image file not exist in path
although the employee no found in database but if image not exist in path when loop crystal report will not open
how to ignore image files not exist in path and open report this is actually what i need
my code below as following
DataTable dt = new DataTable();
string connString = "data source=192.168.1.105; initial catalog=hrdata;uid=sa; password=1234";
using (SqlConnection con = new SqlConnection(connString))
con.Open();
SqlCommand cmd = new SqlCommand("ViewEmployeeNoRall", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
FileStream fs = null;
fs = new FileStream("\\\\192.168.1.105\\Personal Pictures\\" + dr[0] + ".jpg", FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] imgbyte = new byte[fs.Length + 1];
imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
dr["Image"] = imgbyte;
fs.Dispose();
ReportDocument objRpt = new Reports.CrystalReportData2();
objRpt.SetDataSource(dt);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();
and exception error as belowFirst: I created a New Column ("Image") in a datatable of the dataset and change the DataType to System.Byte()
Second : Drag And drop this image Filed Where I want.
private void LoadReport()
frmCheckWeigher rpt = new frmCheckWeigher();
CryRe_DailyBatch report = new CryRe_DailyBatch();
DataSet1TableAdapters.DataTable_DailyBatch1TableAdapter ta = new CheckWeigherReportViewer.DataSet1TableAdapters.DataTable_DailyBatch1TableAdapter();
DataSet1.DataTable_DailyBatch1DataTable table = ta.GetData(clsLogs.strStartDate_rpt, clsLogs.strBatchno_Rpt, clsLogs.cmdeviceid); // Data from Database
DataTable dt = GetImageRow(table, "Footer.Jpg");
report.SetDataSource(dt);
crv1.ReportSource = report;
crv1.Refresh();
By this Function I merge My Image data into dataTable
private DataTable GetImageRow(DataTable dt, string ImageName)
try
FileStream fs;
BinaryReader br;
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + ImageName))
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + ImageName, FileMode.Open);
else
// if photo does not exist show the nophoto.jpg file
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + ImageName, FileMode.Open);
// initialise the binary reader from file streamobject
br = new BinaryReader(fs);
// define the byte array of filelength
byte[] imgbyte = new byte[fs.Length + 1];
// read the bytes from the binary reader
imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
dt.Rows[0]["Image"] = imgbyte;
br.Close();
// close the binary reader
fs.Close();
// close the file stream
catch (Exception ex)
// error handling
MessageBox.Show("Missing " + ImageName + "or nophoto.jpg in application folder");
return dt;
// Return Datatable After Image Row Insertion
Mark as answer or vote as helpful if you find it useful | Ammar Zaied [MCP] -
The name "Folder" does not exist in the namespace
I am trying to learn Wpf and doing some of the examples on the Microsoft site. https://msdn.microsoft.com/en-us/library/vstudio/bb546972(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
I am using Visual studio 2013. As I work through the example I am getting the following error.
Error 1
The name "Folder" does not exist in the namespace "clr-namespace:FolderExplorer".
c:\users\hbrown\documents\visual studio 2013\Projects\FolderExplorer\FolderExplorer\MainWindow.xaml
11 17
FolderExplorer
Error 2
The name "Folder" does not exist in the namespace "clr-namespace:FolderExplorer".
c:\users\hbrown\documents\visual studio 2013\Projects\FolderExplorer\FolderExplorer\MainWindow.xaml
16 7
FolderExplorer
Here is the code:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:FolderExplorer"
Title="Folder Explorer" Height="350" Width="525">
<Window.Resources>
<ObjectDataProvider x:Key="RootFolderDataProvider" >
<ObjectDataProvider.ObjectInstance>
<my:Folder FullPath="C:\"/>
</ObjectDataProvider.ObjectInstance>
</ObjectDataProvider>
<HierarchicalDataTemplate
DataType = "{x:Type my:Folder}"
ItemsSource = "{Binding Path=SubFolders}">
<TextBlock Text="{Binding Path=Name}" />
</HierarchicalDataTemplate>
</Window.Resources>
I have a class file named Folder.vb with this code.
Public Class Folder
Private _folder As DirectoryInfo
Private _subFolders As ObservableCollection(Of Folder)
Private _files As ObservableCollection(Of FileInfo)
Public Sub New()
Me.FullPath = "c:\"
End Sub 'New
Public ReadOnly Property Name() As String
Get
Return Me._folder.Name
End Get
End Property
Public Property FullPath() As String
Get
Return Me._folder.FullName
End Get
Set(value As String)
If Directory.Exists(value) Then
Me._folder = New DirectoryInfo(value)
Else
Throw New ArgumentException("must exist", "fullPath")
End If
End Set
End Property
ReadOnly Property Files() As ObservableCollection(Of FileInfo)
Get
If Me._files Is Nothing Then
Me._files = New ObservableCollection(Of FileInfo)
Dim fi As FileInfo() = Me._folder.GetFiles()
Dim i As Integer
For i = 0 To fi.Length - 1
Me._files.Add(fi(i))
Next i
End If
Return Me._files
End Get
End Property
ReadOnly Property SubFolders() As ObservableCollection(Of Folder)
Get
If Me._subFolders Is Nothing Then
Try
Me._subFolders = New ObservableCollection(Of Folder)
Dim di As DirectoryInfo() = Me._folder.GetDirectories()
Dim i As Integer
For i = 0 To di.Length - 1
Dim newFolder As New Folder()
newFolder.FullPath = di(i).FullName
Me._subFolders.Add(newFolder)
Next i
Catch ex As Exception
System.Diagnostics.Trace.WriteLine(ex.Message)
End Try
End If
Return Me._subFolders
End Get
End Property
End Class
Can someone explain what is happening.
Thanks HalDid you try to build the application (Project->Build in Visual Studio) ? If the error doesn't go away then and you have no other compilation errors (if you do you need to fix these first), you should replace "FolderExplorer" with the namespace
in which the Folder class resides. If you haven't explicitly declared a namespace, you will find the name of the default namespace under Project->Properties->Root namespace. Copy the value from this text box to your XAML:
xmlns:my="clr-namespace:FolderExplorer"
The default namespace is usually the same as the name of the application by default so if your application is called "FolderExplorer" you should be able to build it.
If you cannot make it work then please upload a reproducable sample of your issue to OneDrive and post the link to it here for further help.
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question.
Maybe you are looking for
-
I have problem with buying in games , I got the massage that the purchased can not be completed , please contact iTunes support.. I need help for my case please
-
Please answer these questions.....Urgent
Q You are using Data Guard to ensure high availability. The directory structures on the primary and the standby hosts are different. Referring to the scenario above, what initialization parameter do you set up during configuration of the standby data
-
Macbook Pro randomly restarting since installing Mavericks
Hi guys, I've got a mid-2010 Macbook Pro. Since I installed Mavericks, about 6 months ago, it's started restarting at random (it just goes black and then goes through the reboot cycle. Sometimes it can happen a few times in the same hour - sometimes
-
Action to put 3D watermark on images...
I have an action that puts a 3D watermark diagonally across my image. What I'd LIKE to have it do is properly position itself and scale itself to fit images of different sizes and dimensions....... For example, if my image is 1024x768, my "horizonta
-
I installed ocaml on my Arch system and quickly discovered that when I tried to run the interactive toplevel, the executable complained about missing ledit. Now, I know that ledit is a line editing program written in O'Caml and used by the toplevel.