Showing posts with label simply. Show all posts
Showing posts with label simply. Show all posts

Tuesday, March 20, 2012

ASP 2.0 sql syntax change?

I was simply trying to create a sql command using ASP 2.0 but the syntax appears to have changed. I was trying to write the following:

SqlCommand

cmdUpdateData =newSqlCommand("AddMessage", myConnection);

cmdUpdateData.CommandType = CommandType.StoredProcedure;

But, intellisence will not offer me the second 'CommandType' on the second line?? It works fine using ASP 1.1 but not here on 2.0

Can anyone please help?

Looks ok to me. Are you importing system.data and system.data.sqlclient?|||

Yes I was lacking the system.data namespace!

Many thanks,

James

|||

That all works fine now, but a little further down my code where I fill the datagrid I have another problem with the changing sysntax.

In visual studio 2003 I would use the following:

try

{

//first open the connection

myConnection.Open();

//fill data set with data from sql data adapter

myAdapter.Fill(ds);

//bind the data grid to the datasetthis.dgdShowStudents.DataSource=ds;this.dgdShowStudents.DataKeyField="StudentId";this.dgdShowStudents.DataBind();

However, using ASP2.0 intellisence does not pick up on DataKeyField. Should I be using something else? or do I have to use the wizard for filling a grid. I'd rather do it with code?

|||Is it a datagrid or a gridview?|||GridView. I assumed it would take the same code as the DataGrid|||

If you are using the gridview, I would normally bind it to a sqldatasource control instead of using code. It's a lot simplier and it handles some things very nicely for you (Sortable columns, caching, etc).

The gridview is similiar, but not the same as a datagrid. As for the datakeys, the gridview supports multiple column binding, which I don't believe the datagrid did. I believe the property you are looking for is called DataKeyNames for the gridview.

|||

Many thanks for the help,

James

Friday, February 24, 2012

arrays

Thanks! I am aware that you can't pass an array to an sp. i was aware of tha
t
even when i asked that question. I simply did so, because I needed to prove
this to somebody.
"louise raisbeck" wrote:
> this post was a few days ago so no idea if you will all read this but just
> read this post as need to do a similar thing. this is an open forum to hel
p
> sql developers around the world and Joe your attitude was quite frankly ru
de
> and unnecessary and felt you needn't have bothered with the energy involve
d
> in replying.
> I am also writing a stored procedure and have to put an array of values in
to
> a stored procedure (from an asp.net drop down list). I may be wrong but I
> think that Preeta may have been asking how BEST to handle an array of valu
es,
> not how to declare an array in a stored procedure, which of course you can
t
> do. Preeta I have found that the best way to do this really is to pass a C
SV
> (comma delimited) list of values into a variable of nvarchar then split ou
t
> the values in the stored procedure.
> Or you could do what Joe suggested and go learn how to think and write
> proper sql code and dont ask a question until you do just that!!!!
> regards,
> "Joe Celko" wrote:
>you can't directly pass arrays, at least not in SQL Server.
However, there are some techniques that you can use, see:
http://www.sommarskog.se/arrays-in-sql.html

Thursday, February 9, 2012

Are there any built in aritmetic capabilities on the Date and Time type?

Simply put, I have a 'Date and Time', (06/03/2006 11:40:00), passed to the SelectCommand via the QueryString. I would like to gain data that is between the supplied time and 1 hour prior.
Is there a simple way to take 1 hr off the 'Date and Time" value or is it necessary to build code that parses the string then adjusts it?

The 'Time' and 'TimeStamp' entities below are both of type 'Date and Time' and all values are gained from the same sql database. I.e. the time used as the basis for selecting the hr period is from the same database as the one where the hour period will be selected from.

Any help would be great.

SelectCommand="SELECT [Timestamp], [Volume] FROM [out8$] WHERE (([CustomerLvl1] = @.CustomerLvl1) AND ([Timestamp] = @.Timestamp))">

<SelectParameters>

<asp:QueryStringParameterDefaultValue="TNT Express"Name="CustomerLvl1"QueryStringField="Cust"

Type="String"/>

<asp:QueryStringParameterDefaultValue="20/02/2006 22:20:00"Name="Timestamp"QueryStringField="Time"

Type="DateTime"/>

Perhaps you could do something like this:

SELECT [Timestamp], [Volume] FROM [out8$] WHERE
[CustomerLvl1] = @.CustomerLvl1) AND [Timestamp] >= @.Timestamp ANDDATEDIFF(hh, [TimeStamp],getdate()) =1

|||For future reference, you can view all the Date and Time functions onMSDN here.