what is the best way to identify first row in the following code?
foreach(DataRow row in myrows)
{
if (first row )
{
...do this...
}
else
{
....process other than first rows..
}
}
In SQL Server, it is possible to test the result of a stored procedure to know if the result return rows or nothing ?
Example :
EXEC _sp_MySp 1, 2, 3
IF @@ROWCOUNT = 0
BEGIN
PRINT('Empty')
END
ELSE
BEGIN
PRINT(@@ROWCOUNT)
END
But @@ROWCOUNT always return 0 so maybe is there another way of doing this ?
I'm trying to learn how to use keys and to break the habit of necessarily having SERIAL type IDs for all rows in all my tables. At the same time, I'm also doing many-to-many relationships, and so requiring unique values on either column of the tables that coordinate the relationships would hamper that.
How can I define a primary key on a table such that any given value can be repeated in any column, so long as the combination of values across all columns is never repeated exactly?
How to validate a textarea in a form.i.e, it should not be empty or have any new lines and if so raise an alert
<script>
function val()
{
//ifnewline found or blank raise an alert
}
</script>
<form>
<textarea name = "pt_text" rows = "8" cols = "8" class = "input" WRAP ></textarea>
<input type=""button" onclick="val();"
</form>
Thanks
What are the differences between the two queries?
SELECT CountryMaster.Id
FROM Districts INNER JOIN
CountryMaster ON Districts.CountryId = CountryMaster.Id
SELECT CountryMaster.Id
FROM CountryMaster INNER JOIN
Districts ON Districts.CountryId = CountryMaster.Id
Please mind the
i) Table positions and second
ii) On Fields
As I know, output will be same. But I want to know, is there any drastic effects of the same if I neglect positions of tables and columns in complex queries or tables having tons of data like thousands and lakhs of rows...
I have extended some functionality to a DataContext object (called "CodeLookupAccessDataContext") such that the object exposes some methods to return results of LINQ to SQL queries. Here are the methods I have defined:
public List<CompositeSIDMap> lookupCompositeSIDMap(int regionId, int marketId)
{
var sidGroupId = CompositeSIDGroupMaps.Where(x => x.RegionID.Equals(regionId) && x.MarketID.Equals(marketId))
.Select(x => x.CompositeSIDGroup);
IEnumerator<int> sidGroupIdEnum = sidGroupId.GetEnumerator();
if (sidGroupIdEnum.MoveNext())
return lookupCodeInfo<CompositeSIDMap, CompositeSIDMap>(x => x.CompositeSIDGroup.Equals(sidGroupIdEnum.Current), x => x);
else
return null;
}
private List<TResult> lookupCodeInfo<T, TResult>(Func<T, bool> compLambda, Func<T, TResult> selectLambda)
where T : class
{
System.Data.Linq.Table<T> dataTable = this.GetTable<T>();
var codeQueryResult = dataTable.Where(compLambda)
.Select(selectLambda);
List<TResult> codeList = new List<TResult>();
foreach (TResult row in codeQueryResult)
codeList.Add(row);
return codeList;
}
CompositeSIDGroupMap and CompositeSIDMap are both tables in our database that are represented as objects in my DataContext object. I wrote the following code to call these methods and display the T-SQL generated after calling these methods:
using (CodeLookupAccessDataContext codeLookup = new CodeLookupAccessDataContext())
{
codeLookup.Log = Console.Out;
List<CompositeSIDMap> compList = codeLookup.lookupCompositeSIDMap(5, 3);
}
I got the following results in my log after invoking this code:
SELECT [t0].[CompositeSIDGroup]
FROM [dbo].[CompositeSIDGroupMap] AS [t0]
WHERE ([t0].[RegionID] = @p0) AND ([t0].[MarketID] = @p1)
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [5]
-- @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [3]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1
SELECT [t0].[PK_CSM], [t0].[CompositeSIDGroup], [t0].[InputSID], [t0].[TargetSID], [t0].[StartOffset], [t0].[EndOffset], [t0].[Scale]
FROM [dbo].[CompositeSIDMap] AS [t0]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1
The first T-SQL statement contains a where clause as specified and returns one column as expected. However, the second statement is missing a where clause and returns all columns, even though I did specify which rows I wanted to view and which columns were of interest. Why is the second T-SQL statement generated the way it is, and what should I do to ensure that I filter out the data according to specifications via the T-SQL?
Also note that I would prefer to keep lookupCodeInfo() and especially am interested in keeping it enabled to accept lambda functions for specifying which rows/columns to return.
I want to use linq to get datarow array from a datatable which its string type ColumnA is not null or depending on its length 0 , so I can get the row index with Indexof() method to deal with something else.
ColumnA ColumnB ColumnC
A0 B0 C0
Null B1 C1
A2 B2 C2
Null B3 C3
My Linq Statment:
DataRow[] rows = myDataTable.Select("ColumnA is not null").Where(row=>row.Field<string>("ColumnA").Length>0);
somebody who can help?
Which is the most effective way to sum data in the DataTable by a given criteria?
I have the following table:
KEY_1
KEY_2,
VALUE_1,
VALUE_2
Input:
01101, P, 2, 3
01101, F, 1, 1
01101, P, 4, 4
10102, F, 5, 7
Desired output (new DataTable):
01101, P, 6, 7
01101, F, 1, 1
01101, SUM, 7, 8
10102, F, 5, 7
10102, SUM, 5, 7
I need efficient algorithm, because I have 10k rows and 18 columns in a DataTable.
Thank you.
Let's say I have a table with millions of rows. Using JPA, what's the proper way to iterate over a query against that table, such that I don't have all an in-memory List with millions of objects?
I suspect that the following will blow up if the table is large:
List<Model> models = entityManager().createQuery("from Model m", Model.class).getResultList();
for (Model model : models)
{
// do something with model
}
Is pagination (looping and manually updating setFirstResult()/setMaxResult()) really the best solution?
i have forum_topics table and have topics_posts table
now i want to select from forum_topics where have no posts from topics_posts
can any one give me the one syntax like this
selct from * forum_topics where have no rows in topics_posts table
Hi,
I have datatable with column name tag and 100 rows of data.I need to filter this table with tag starting with "UNKNOWN".
What should my sortexpression for datatable.select be ?
I'm trying the following.
Datarow[] abc = null;
abc = dtTagList.Select(string.format("tag='{0}'","UNKNOWN"))
How can I achieve tag startswith 'UNKNOWN' in the above code ?
Im using python to access a MySQL database and im getting a unknown column in field due to quotes not being around the variable.
code below:
cur = x.cnx.cursor()
cur.execute('insert into tempPDBcode (PDBcode) values (%s);' % (s))
rows = cur.fetchall()
How do i manually insert double or single quotes around the value of s?
I've trying using str() and manually concatenating quotes around s but it still doesn't work.
The sql statement works fine iv double and triple check my sql query.
I have a table for users:
USERS:
ID | NAME |
----------------
1 | JOHN |
2 | STEVE |
a table for computers:
COMPUTERS:
ID | USER_ID |
------------------
13 | 1 |
14 | 1 |
a table for processors:
PROCESSORS:
ID | NAME |
---------------------------
27 | PROCESSOR TYPE 1 |
28 | PROCESSOR TYPE 2 |
and a table for harddrives:
HARDDRIVES:
ID | NAME |
---------------------------|
35 | HARDDRIVE TYPE 25 |
36 | HARDDRIVE TYPE 90 |
Each computer can have many attributes from the different attributes tables (processors, harddrives etc), so I have intersection tables like this, to link the attributes to the computers:
COMPUTER_PROCESSORS:
C_ID | P_ID |
--------------|
13 | 27 |
13 | 28 |
14 | 27 |
COMPUTER_HARDDRIVES:
C_ID | H_ID |
--------------|
13 | 35 |
So user JOHN, with id 1 owns computer 13 and 14. Computer 13 has processor 27 and 28, and computer 13 has harddrive 35. Computer 14 has processor 27 and no harddrive.
Given a user's id, I would like to retrieve a list of that user's computers with each computers attributes.
I have figured out a query that gives me a somewhat of a result:
SELECT computers.id, processors.id AS p_id, processors.name AS p_name, harddrives.id AS h_id, harddrives.name AS h_name,
FROM computers
JOIN computer_processors ON (computer_processors.c_id = computers.id)
JOIN processors ON (processors.id = computer_processors.p_id)
JOIN computer_harddrives ON (computer_harddrives.c_id = computers.id)
JOIN harddrives ON (harddrives.id = computer_harddrives.h_id)
WHERE computers.user_id = 1
Result:
ID | P_ID | P_NAME | H_ID | H_NAME |
-----------------------------------------------------------
13 | 27 | PROCESSOR TYPE 1 | 35 | HARDDRIVE TYPE 25 |
13 | 28 | PROCESSOR TYPE 2 | 35 | HARDDRIVE TYPE 25 |
But this has several problems...
Computer 14 doesnt show up, because it has no harddrive.
Can I somehow make an OUTER JOIN to make sure that all computers show up, even if there a some attributes they don't have?
Computer 13 shows up twice, with the same harddrive listet for both. When more attributes are added to a computer (like 3 blocks of ram), the number of rows returned for that computer gets pretty big, and it makes it had to sort the result out in application code. Can I somehow make a query, that groups the two returned rows together? Or a query that returns NULL in the h_name column in the second row, so that all values returned are unique?
EDIT:
What I would like to return is something like this:
ID | P_ID | P_NAME | H_ID | H_NAME |
-----------------------------------------------------------
13 | 27 | PROCESSOR TYPE 1 | 35 | HARDDRIVE TYPE 25 |
13 | 28 | PROCESSOR TYPE 2 | 35 | NULL |
14 | 27 | PROCESSOR TYPE 1 | NULL | NULL |
Or whatever result that make it easy to turn it into an array like this
[13] =>
[P_NAME] =>
[0] => PROCESSOR TYPE 1
[1] => PROCESSOR TYPE 2
[H_NAME] =>
[0] => HARDDRIVE TYPE 25
[14] =>
[P_NAME] =>
[0] => PROCESSOR TYPE 1
I have to make a process in Oracle/PLSQL. I have to verify that the interval of time between start_date and end_date from a new row that I create must not intersect other start_dates and end_dates from other rows.
Now I need to check each row for that condition and if it doesn't correspond the repetitive instruction should stop and after that to display a message such as "The interval of time given is not correct".
I don't know how to make repetitive instructions in Oracle/PLSQL and I would appreciate if you would help me.
What am I doing wrong here? I am trying to limit my xpath search to a specific row in my table but my query always returns the content of the span in the first row:
var query = "//span[contains(@id, 'timer')]";
var root = document.getElementById('movements').rows[1];
document.evaluate(query, root, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent
Please help!
Using jquery, when a button is clicked (server side), I want to append #button to the url.
This will only be used when there is validation errors, I want the browser to scroll to the bottom where the button is.
I already tried MaintainScrollPositionOnPostback but it doesn't work here since the validation rows are made visible upon clicking the button.
I have a table in my form, where I put n-rows, every row contains 1 RadioButtonList, when user select the item in RadioButtonList, I need to get number of selected Item, without updating the page.
Dear overflowers,
I have a rather large dataset in a long format where I need to count the number of instances of the ID due to two different variables, A & B. E.g. The same person can be represented in multiple rows due to either A or B. What I need to do is to count the number of instances of ID which is not too hard, but also count the number of ID due to A and B and return these as variables in the dataset.
Regards,
//Mi
Take this simple query:
SELECT DATE_FORMAT(someDate, '%y-%m-%d') as formattedDay
FROM someTable
GROUP BY formatterDay
This will select rows from a table with only 1 row per date.
How do I ensure that the row selected per date is the earliest for that date, without doing an ordered subquery in the FROM?
Cheers
Hi, I have a mysql table that I need to only contain 20 newest records before adding additional records.
New rows are added daily so I would like it first delete any records that are greater than the 20 allowed starting with the earliest.
The table contains an auto increment "id" column so I can easily determine which is the earliest records.
Thanks for any help.
Hello All
I am using this toolkit to write Excel.Every thing is fine with this, but i am not getting how can i inset image and also put style on some rows on my excel
http://excelpackage.codeplex.com/wikipage?title=Creating%20an%20Excel%20spreadsheet%20from%20scratch&referringTitle=Home
i am using c#
Hi,
I have following SQL tables.
ImportantMessages
impID
Message
ImportantMessageUsers
imuID
imuUserID
imuImpID
I want to write a Linq2Sql query so that it returns any rows from ImportantMessages
that does not have a record in ImportantMessagesUsers.
Matchiing fields are
impID ----- imuImpID
Assume imuUserID of 6
Is there any way to get the if statement to evaluate a query?
SELECT if(50,'EQ_Type','*') FROM EQUIPMENT;
Resulting in:
+-----------------------+
| IF(50,'EQ_Type','*') |
+-----------------------+
| EQ_Type |
| EQ_Type |
| EQ_Type |
| EQ_Type |
| EQ_Type |
| EQ_Type |
| EQ_Type |
| EQ_Type |
| EQ_Type |
+-----------------------+
9 rows in set (0.00 sec)
I would like the above statement to be equivalent to the following:
SELECT 'EQ_Type' FROM EQUIPMENT;
And produce:
+--------------+
| EQ_Type |
+--------------+
| ENGINE |
| ENGINE |
| ENGINE |
| TRAILER |
| TRAILER |
| TRAILER |
| WATER TENDER |
| WATER TENDER |
| WATER TENDER |
+--------------+
Thanks for any help