Showing posts with label stuck. Show all posts
Showing posts with label stuck. Show all posts

Friday, March 30, 2012

Need help building/reading C# SQL Array

I'm stuck and uinder a bit of a time crunch.

I have 5 fields I want to get out of a sql database using a function that I'm writing. I figure it sounds like an array. basically I want to make an array, and fill it up with the results of a sql select, then read the array.

This is what I have so far....

String TempHRAcctCode, TempJobDescription, TempHourlyRate, TempEmplID;
Array TempArray;
TempJobDescription = DDDept.SelectedItem.Text; (to get KeY Value)

SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MYCONN"].ToString());
connection.Open();
SqlCommand command = new SqlCommand("Select HRAcctCode, HourlyRate , EmplID, ... FROM TimeMyProfile WHERE JobDescription = " + TempJobDescription + " ", connection);
SqlDataReader TempDataReader = command.ExecuteReader;
while TempDataReader.Read
(
... OK I GIVE UP!

Thanks in advance



why you want read as an array ?? If you really want to read these data later then load into aDataSetrather than reading from Data Reader into an array and then later read again the array...

using (SqlDataAdapter da = new SqlDataAdapter(command))
{
DataSet ds = new DataSet();

// Fill the DataSet using default values for DataTable names, etc
da.Fill(ds);

connection.Close();

// Return the dataset
return ds;
}

And you can read the data set like

foreach (DataRow dr in ds.Tables[0] .Rows)

{

string myVar = dr["HourlyRate"].ToString()

}

|||

Funny thing is, as I was typing th equestion I was asking myself the same thing, WHY use an array!
Excellent suggestion, it works GREAAT!

Thanks

Monday, March 26, 2012

Need Help

Hi there,

I want to achive the following but stuck big time.

I got a table with the following values for eg

ID Name Created
1 ABC 01/02/06
1 DEF 03/02/06
1 ABC 04/02/06
2 SDF 02/02/06
3 DEF 03/02/06
3 ABC 04/02/06

I want to achive it as

ID Name1 Name2 Name3
1 ABC DEF ABC
2 SDF
3 DEF ABC

Is there any way around this. I'm using views from SLQ server database.

ThanksU can write a procedure to export data in that format to a text file, then use that text file to make ur report. There may be an easy way as well
Raheem AHmed

Monday, March 19, 2012

Need all Rows:Outer Join + WHERE

Hi, I would appreciate help on the following query I got stuck with;

I've got 2 tables "AccountList" and "PeriodBalance";

I need to return all the accounts form "AccountList" and their balance form "PeriodBalance";

The user will select a period for which the balances should be returned, if there is no balance for the period... 0 should be returned. "PeriodBalance" would not have an entry if there is no balance for the period.

There is only 3 possible periods (1, 2 or 3)

And there is only one balance per period per account;

TABEL 1: AccountList:

AccNo

100

200

300

TABLE 2: PeriodBalance:

AccNo PerID PerBal

100 1 1000

100 2 1750

100 3 1800

300 1 3200

300 3 3500

This is what is what I need returned by the query, assuming we are selecting PerID 2: (WHERE PerID=2)

AccNo PerID PerBal

100 2 1750

200 2 0

300 2 0

I've included ISNULL(PerID,4) = 4 in my WHERE clause...this worked for returning AccNo 200.

My problem is AccNo 300 in not NULL....it has values, just not for the selected PerID...so how do I get AccNo 300 to be included in my Query result?

This is my SQL Query:

SELECT AccountList.AccNo, PeriodBalance.PerID, PeriodBalance.PerBal

FROM AccountList LEFT OUTER JOIN

PeriodBalance ON AccountList.AccNo = PeriodBalance.AccNo

WHERE PeriodBalance.PerID = 2 OR ISNULL(PerID,4) = 4

Thanks in advance;

You should move the filter expression from the "where" clause to the "join".

...

on a.AccNo = p.AccNo and (p.PerID = 2 or p.PerID is null)

AMB

|||

Try this Query

select accountlst.accno,per.perid,per.perbal from
accountlst
left outer join
(select * from PeriodBalance where perid=2) per
on accountlst .accno = per.accno

her u get Perid as null. For this u can replace Per.Perid with the paramter for select perid

declare @.perid int

set @.perid = 2

select accountlst.accno,@.perid,per.perbal from
accountlst
left outer join
(select * from PeriodBalance where perid=@.perid) per
on accountlst .accno = per.accno

|||

Thank you very much Hunchback! That worked just great!

Saturday, February 25, 2012

Need a good insert statement

Hi, I need some help. I've spent nearly a w of work and lunch time trying
to crack this nut, and I guess I am finally stuck.
I have a table with financial data like invoices. The tables are huge.
Hundreds of millions of rows per year.
I want to store some additional information related to gambling in one of
these tables.
I want to put this new data way off in the corner of the table temporarily
until I am able to come back to work.
For reasons that are private, I do not want to create a new table.
So if I could stick this information out starting at say row 104,000 and
column 333,000 that would be great. No one's going to look there. And if
they do it will look like some kind of mistake. I can't figure out how to
get the data there.
Any good Ideas would naturally be of great help. Also, since I am in sort of
a hurry (tax day is april 15) I would really appreciate it if I could just
get some of those "only the quality answers." I know a lot of people like to
yik yak, but I just need da facts. Thanks a lot!Hi
I'm not sure I understand you. Do you want to add additional column? If you
do , use ALTER TABLE TableName ADD Column.....
If you want to do paging I'd recomend you vist Aaron's web site
www.aspfaq.com .
"TargetBleigh" <ddsd*f.com> wrote in message
news:2c6dnRzmUNP2ec3fRVn-1g@.comcast.com...
> Hi, I need some help. I've spent nearly a w of work and lunch time
trying
> to crack this nut, and I guess I am finally stuck.
> I have a table with financial data like invoices. The tables are huge.
> Hundreds of millions of rows per year.
> I want to store some additional information related to gambling in one of
> these tables.
> I want to put this new data way off in the corner of the table temporarily
> until I am able to come back to work.
> For reasons that are private, I do not want to create a new table.
> So if I could stick this information out starting at say row 104,000 and
> column 333,000 that would be great. No one's going to look there. And if
> they do it will look like some kind of mistake. I can't figure out how to
> get the data there.
> Any good Ideas would naturally be of great help. Also, since I am in sort
of
> a hurry (tax day is april 15) I would really appreciate it if I could just
> get some of those "only the quality answers." I know a lot of people like
to
> yik yak, but I just need da facts. Thanks a lot!
>